In [1]:
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
from scipy import stats
import seaborn as sns

1.) UPLOADING DATA & CREATING DATA TABLES

1.1 Oil price

In [2]:
#WTI #Brent #Eternal #Gasoline
oil_price = pd.read_csv('Weekly_data_csv_v4.csv')
In [3]:
oil_price.columns
Out[3]:
Index(['Weekindex', 'Date', 'Year', 'Month', 'Week', 'Day', 'Par_Month',
       'Par_Week', 'Par_Day', 'oil_spot_WTI', 'oil_spot_Brent',
       'future_oil_contract_1', 'future_oil_contract_2',
       'future_oil_contract_3', 'future_oil_contract_4', 'Gasoline_Price_US',
       'sugar_price_us', 'ethanol_price_us', 'Dummy_Financial_crisis',
       'chg_oil_spot_WTI', 'chg_oil_spot_Brent', 'chg_oil_future_contract1',
       'chg_oil_future_contract2', 'chg_oil_future_contract3',
       'chg_oil_future_contract4', 'chg_Gasoline_price_US',
       'chg_Sugar_price_US', 'chg_ethanol_price_US',
       'chg_oil_spot_WTI_Positive', 'chg_oil_spot_Brent_Positive',
       'chg_oil_future_contract1_Positive',
       'chg_oil_future_contract2_Positive',
       'chg_oil_future_contract3_Positive',
       'chg_oil_future_contract4_Positive', 'chg_Gasoline_price_US_Positive',
       'chg_Sugar_price_US_Positive', 'chg_ethanol_price_US_Positive',
       'chg_oil_spot_WTI_Negative', 'chg_oil_spot_Brent_Negative',
       'chg_oil_future_contract1_Negative',
       'chg_oil_future_contract2_Negative',
       'chg_oil_future_contract3_Negative',
       'chg_oil_future_contract4_Negative', 'chg_Gasoline_price_US_Negative',
       'chg_Sugar_price_US_Negative', 'chg_ethanol_price_US_Negative',
       'chg_Gasoline_price_US_future'],
      dtype='object')
In [4]:
oil_price = oil_price[['Weekindex', 'Date', 'Year', 'Month', 'Week', 'Day', 'Par_Month','Par_Week','Par_Day', 'oil_spot_WTI','oil_spot_Brent','future_oil_contract_1','sugar_price_us', 'ethanol_price_us','chg_oil_spot_WTI','chg_oil_spot_Brent','chg_oil_spot_WTI_Positive','chg_oil_spot_WTI_Negative','chg_oil_future_contract1','chg_oil_future_contract1_Positive','chg_oil_future_contract1_Negative','Gasoline_Price_US','chg_Gasoline_price_US','chg_Gasoline_price_US_Positive','chg_Gasoline_price_US_future']]
In [5]:
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
import matplotlib.cbook as cbook
from datetime import datetime, date
from dateutil.relativedelta import relativedelta

oil_price['Date_edited'] = oil_price['Date'].apply(lambda x : datetime.strptime( x,'%m/%d/%Y') )

years = mdates.YearLocator()   # every year
months = mdates.MonthLocator()  # every month
years_fmt = mdates.DateFormatter('%Y')


fig, ax = plt.subplots(figsize = (15,8))
ax.plot('Date_edited', 'oil_spot_WTI', data=oil_price, color = 'tab:blue')

# format the ticks
ax.xaxis.set_major_locator(years)
ax.xaxis.set_major_formatter(years_fmt)
ax.xaxis.set_minor_locator(months)

# round to nearest years.
datemin = np.datetime64(list(oil_price['Date_edited'])[0].strftime('%Y-%m-%d'),'Y')
datemax = np.datetime64(list(oil_price['Date_edited'])[-1].strftime('%Y-%m-%d'),'Y') + np.timedelta64(1, 'Y')
#datemin = datetime.strptime(list(oil_price['Date'])[0],'%m/%d/%Y')
#datemax = datetime.strptime(list(oil_price['Date'])[-1],'%m/%d/%Y') + relativedelta(years=1)
ax.set_xlim(datemin, datemax)

# format the coords message box
ax.format_xdata = mdates.DateFormatter('%Y-%m-%d')
ax.format_ydata = lambda x: '$%1.2f' % x  # format the price.
ax.grid(True)

ax.set_xlabel('Year',fontdict={'fontsize': 15, 'fontweight': 'medium'})
ax.set_ylabel('Oil spot WTI',fontdict={'fontsize': 15, 'fontweight': 'medium'})
ax.set_title('Change in oil price since 1991 ', fontdict={'fontsize': 20, 'fontweight': 'medium'})


ax2 = ax.twinx()  # instantiate a second axes that shares the same x-axis

#color = color = 'tab:blue'
ax2.plot('Date_edited', 'chg_oil_spot_WTI', data=oil_price, color = 'tab:grey', alpha=0.2)

ax2.tick_params(axis = 'y') #,labelcolor = color)
ax2.set_ylabel('Change in oil price WTI', size = 15)

ax3 = ax.twinx()


break_year = np.datetime64(date(2008, 1, 1).strftime('%Y-%m-%d'),'Y')
ax3.axvline(break_year, ls='--', color='r', alpha = 0.5)
ax3.axis('off')

ax4 = ax.twinx()


break_year = np.datetime64(date(2010, 1, 1).strftime('%Y-%m-%d'),'Y')
ax4.axvline(break_year, ls='--', color='r', alpha = 0.5)
ax4.axis('off')

# rotates and right aligns the x labels, and moves the bottom of the
# axes up to make room for them
fig.autofmt_xdate()

plt.show()
In [6]:
oil_price_modified = oil_price.copy()
year_53 = [1992,1998,2004,2009,2015,2020]
for i in year_53:
    week = oil_price_modified[oil_price_modified['Year'] == 53]['Week']
    oil_price_modified[oil_price_modified['Week'] == 53]['Week'] = 1
    oil_price_modified[oil_price_modified['Week'] == 53]['Year'] = i+1
oil_price_modified[oil_price_modified['Year'] == 1992]
C:\Users\DELL\Anaconda3\lib\site-packages\ipykernel_launcher.py:5: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  """
C:\Users\DELL\Anaconda3\lib\site-packages\ipykernel_launcher.py:6: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  
C:\Users\DELL\Anaconda3\lib\site-packages\ipykernel_launcher.py:5: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  """
C:\Users\DELL\Anaconda3\lib\site-packages\ipykernel_launcher.py:6: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  
C:\Users\DELL\Anaconda3\lib\site-packages\ipykernel_launcher.py:5: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  """
C:\Users\DELL\Anaconda3\lib\site-packages\ipykernel_launcher.py:6: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  
C:\Users\DELL\Anaconda3\lib\site-packages\ipykernel_launcher.py:5: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  """
C:\Users\DELL\Anaconda3\lib\site-packages\ipykernel_launcher.py:6: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  
C:\Users\DELL\Anaconda3\lib\site-packages\ipykernel_launcher.py:5: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  """
C:\Users\DELL\Anaconda3\lib\site-packages\ipykernel_launcher.py:6: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  
C:\Users\DELL\Anaconda3\lib\site-packages\ipykernel_launcher.py:5: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  """
C:\Users\DELL\Anaconda3\lib\site-packages\ipykernel_launcher.py:6: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  
Out[6]:
Weekindex Date Year Month Week Day Par_Month Par_Week Par_Day oil_spot_WTI ... chg_oil_spot_WTI_Positive chg_oil_spot_WTI_Negative chg_oil_future_contract1 chg_oil_future_contract1_Positive chg_oil_future_contract1_Negative Gasoline_Price_US chg_Gasoline_price_US chg_Gasoline_price_US_Positive chg_Gasoline_price_US_future Date_edited
48 314 1/3/1992 1992 1 1 3 199201 19920101 19921103 19.22 ... 0.021031 0.000000 0.024745 0.024745 0.000000 1.053 -0.009452 0.000000 -0.011226 1992-01-03
49 315 1/10/1992 1992 1 2 10 199201 19920102 19921110 18.26 ... 0.000000 -0.051239 -0.053403 0.000000 -0.053403 1.042 -0.010501 0.000000 -0.009452 1992-01-10
50 316 1/17/1992 1992 1 3 17 199201 19920103 19921117 19.11 ... 0.045499 0.000000 0.049756 0.049756 0.000000 1.026 -0.015474 0.000000 -0.010501 1992-01-17
51 317 1/24/1992 1992 1 4 24 199201 19920104 19921124 18.75 ... 0.000000 -0.019018 -0.008386 0.000000 -0.008386 1.014 -0.011765 0.000000 -0.015474 1992-01-24
52 318 1/31/1992 1992 1 5 31 199201 19920105 19921131 18.93 ... 0.009554 0.000000 -0.005277 0.000000 -0.005277 1.006 -0.007921 0.000000 -0.011765 1992-01-31
53 319 2/7/1992 1992 2 6 7 199202 19920206 19921107 19.91 ... 0.050474 0.000000 0.050049 0.050049 0.000000 0.995 -0.010995 0.000000 -0.007921 1992-02-07
54 320 2/14/1992 1992 2 7 14 199202 19920207 19921114 19.42 ... 0.000000 -0.024919 -0.020850 0.000000 -0.020850 1.004 0.009005 0.009005 -0.010995 1992-02-14
55 321 2/21/1992 1992 2 8 21 199202 19920208 19921121 18.60 ... 0.000000 -0.043142 -0.041979 0.000000 -0.041979 1.011 0.006948 0.006948 0.009005 1992-02-21
56 322 2/28/1992 1992 2 9 28 199202 19920209 19921128 18.69 ... 0.004827 0.000000 0.001071 0.001071 0.000000 1.014 0.002963 0.002963 0.006948 1992-02-28
57 323 3/6/1992 1992 3 10 6 199203 19920310 19921106 18.53 ... 0.000000 -0.008598 -0.009142 0.000000 -0.009142 1.012 -0.001974 0.000000 0.002963 1992-03-06
58 324 3/13/1992 1992 3 11 13 199203 19920311 19921113 19.16 ... 0.033434 0.000000 0.035557 0.035557 0.000000 1.013 0.000988 0.000988 -0.001974 1992-03-13
59 325 3/20/1992 1992 3 12 20 199203 19920312 19921120 18.78 ... 0.000000 -0.020032 -0.014706 0.000000 -0.014706 1.010 -0.002966 0.000000 0.000988 1992-03-20
60 326 3/27/1992 1992 3 13 27 199203 19920313 19921127 19.19 ... 0.021597 0.000000 0.013663 0.013663 0.000000 1.015 0.004938 0.004938 -0.002966 1992-03-27
61 327 4/3/1992 1992 4 14 3 199204 19920414 19921103 20.25 ... 0.053765 0.000000 0.057303 0.057303 0.000000 1.013 -0.001972 0.000000 0.004938 1992-04-03
62 328 4/10/1992 1992 4 15 10 199204 19920415 19921110 20.45 ... 0.009828 0.000000 0.007366 0.007366 0.000000 1.026 0.012752 0.012752 -0.001972 1992-04-10
63 329 4/16/1992 1992 4 16 16 199204 19920416 19921116 20.25 ... 0.000000 -0.009828 -0.011316 0.000000 -0.011316 1.051 0.024074 0.024074 0.012752 1992-04-16
64 330 4/24/1992 1992 4 17 24 199204 19920417 19921124 20.05 ... 0.000000 -0.009926 0.000495 0.000495 0.000000 1.058 0.006638 0.006638 0.024074 1992-04-24
65 331 5/1/1992 1992 5 18 1 199205 19920518 19921101 20.88 ... 0.040563 0.000000 0.030682 0.030682 0.000000 1.072 0.013146 0.013146 0.006638 1992-05-01
66 332 5/8/1992 1992 5 19 8 199205 19920519 19921108 20.85 ... 0.000000 -0.001438 0.000480 0.000480 0.000000 1.089 0.015734 0.015734 0.013146 1992-05-08
67 333 5/15/1992 1992 5 20 15 199205 19920520 19921115 20.70 ... 0.000000 -0.007220 -0.008183 0.000000 -0.008183 1.102 0.011867 0.011867 0.015734 1992-05-15
68 334 5/22/1992 1992 5 21 22 199205 19920521 19921122 20.79 ... 0.004338 0.000000 0.012011 0.012011 0.000000 1.118 0.014415 0.014415 0.011867 1992-05-22
69 335 5/29/1992 1992 5 22 29 199205 19920522 19921129 22.13 ... 0.062462 0.000000 0.054369 0.054369 0.000000 1.120 0.001787 0.001787 0.014415 1992-05-29
70 336 6/5/1992 1992 6 23 5 199206 19920623 19921205 22.65 ... 0.023226 0.000000 0.022804 0.022804 0.000000 1.128 0.007117 0.007117 0.001787 1992-06-05
71 337 6/12/1992 1992 6 24 12 199206 19920624 19921212 22.28 ... 0.000000 -0.016470 -0.014248 0.000000 -0.014248 1.143 0.013210 0.013210 0.007117 1992-06-12
72 338 6/19/1992 1992 6 25 19 199206 19920625 19921219 22.16 ... 0.000000 -0.005401 -0.001795 0.000000 -0.001795 1.151 0.006975 0.006975 0.013210 1992-06-19
73 339 6/26/1992 1992 6 26 26 199206 19920626 19921226 22.42 ... 0.011665 0.000000 0.008054 0.008054 0.000000 1.153 0.001736 0.001736 0.006975 1992-06-26
74 340 7/3/1992 1992 7 27 3 199207 19920727 19921203 22.08 ... 0.000000 -0.015281 -0.022078 0.000000 -0.022078 1.149 -0.003475 0.000000 0.001736 1992-07-03
75 341 7/10/1992 1992 7 28 10 199207 19920728 19921210 21.25 ... 0.000000 -0.038315 -0.030999 0.000000 -0.030999 1.147 -0.001742 0.000000 -0.003475 1992-07-10
76 342 7/17/1992 1992 7 29 17 199207 19920729 19921217 21.56 ... 0.014483 0.000000 0.013999 0.013999 0.000000 1.139 -0.006999 0.000000 -0.001742 1992-07-17
77 343 7/24/1992 1992 7 30 24 199207 19920730 19921224 21.95 ... 0.017927 0.000000 0.018366 0.018366 0.000000 1.132 -0.006165 0.000000 -0.006999 1992-07-24
78 344 7/31/1992 1992 7 31 31 199207 19920731 19921231 21.83 ... 0.000000 -0.005482 -0.005017 0.000000 -0.005017 1.128 -0.003540 0.000000 -0.006165 1992-07-31
79 345 8/7/1992 1992 8 32 7 199208 19920832 19921207 21.27 ... 0.000000 -0.025988 -0.030172 0.000000 -0.030172 1.126 -0.001775 0.000000 -0.003540 1992-08-07
80 346 8/14/1992 1992 8 33 14 199208 19920833 19921214 21.31 ... 0.001879 0.000000 0.002824 0.002824 0.000000 1.123 -0.002668 0.000000 -0.001775 1992-08-14
81 347 8/21/1992 1992 8 34 21 199208 19920834 19921221 21.19 ... 0.000000 -0.005647 -0.009443 0.000000 -0.009443 1.116 -0.006253 0.000000 -0.002668 1992-08-21
82 348 8/28/1992 1992 8 35 28 199208 19920835 19921228 21.30 ... 0.005178 0.000000 0.010852 0.010852 0.000000 1.123 0.006253 0.006253 -0.006253 1992-08-28
83 349 9/4/1992 1992 9 36 4 199209 19920936 19921204 21.77 ... 0.021826 0.000000 0.021356 0.021356 0.000000 1.121 -0.001783 0.000000 0.006253 1992-09-04
84 350 9/11/1992 1992 9 37 11 199209 19920937 19921211 22.00 ... 0.010510 0.000000 0.010964 0.010964 0.000000 1.121 0.000000 0.000000 -0.001783 1992-09-11
85 351 9/18/1992 1992 9 38 18 199209 19920938 19921218 21.96 ... 0.000000 -0.001820 -0.001364 0.000000 -0.001364 1.124 0.002673 0.002673 0.000000 1992-09-18
86 352 9/25/1992 1992 9 39 25 199209 19920939 19921225 21.51 ... 0.000000 -0.020705 -0.013743 0.000000 -0.013743 1.123 -0.000890 0.000000 0.002673 1992-09-25
87 353 10/2/1992 1992 10 40 2 199210 19921040 19921202 21.93 ... 0.019338 0.000000 0.011009 0.011009 0.000000 1.118 -0.004462 0.000000 -0.000890 1992-10-02
88 354 10/9/1992 1992 10 41 9 199210 19921041 19921209 21.99 ... 0.002732 0.000000 0.020321 0.020321 0.000000 1.115 -0.002687 0.000000 -0.004462 1992-10-09
89 355 10/16/1992 1992 10 42 16 199210 19921042 19921216 22.31 ... 0.014447 0.000000 -0.004031 0.000000 -0.004031 1.115 0.000000 0.000000 -0.002687 1992-10-16
90 356 10/23/1992 1992 10 43 23 199210 19921043 19921223 21.11 ... 0.000000 -0.055288 -0.050160 0.000000 -0.050160 1.113 -0.001795 0.000000 0.000000 1992-10-23
91 357 10/30/1992 1992 10 44 30 199210 19921044 19921230 20.68 ... 0.000000 -0.020580 -0.027268 0.000000 -0.027268 1.113 0.000000 0.000000 -0.001795 1992-10-30
92 358 11/6/1992 1992 11 45 6 199211 19921145 19921206 20.26 ... 0.000000 -0.020519 -0.015641 0.000000 -0.015641 1.120 0.006270 0.006270 0.000000 1992-11-06
93 359 11/13/1992 1992 11 46 13 199211 19921146 19921213 20.04 ... 0.000000 -0.010918 -0.010897 0.000000 -0.010897 1.120 0.000000 0.000000 0.006270 1992-11-13
94 360 11/20/1992 1992 11 47 20 199211 19921147 19921220 20.37 ... 0.016333 0.000000 0.015811 0.015811 0.000000 1.112 -0.007168 0.000000 0.000000 1992-11-20
95 361 11/27/1992 1992 11 48 27 199211 19921148 19921227 20.29 ... 0.000000 -0.003935 0.005768 0.005768 0.000000 1.106 -0.005410 0.000000 -0.007168 1992-11-27
96 362 12/4/1992 1992 12 49 4 199212 19921249 19921204 18.95 ... 0.000000 -0.068324 -0.080026 0.000000 -0.080026 1.098 -0.007260 0.000000 -0.005410 1992-12-04
97 363 12/11/1992 1992 12 50 11 199212 19921250 19921211 19.09 ... 0.007361 0.000000 0.007889 0.007889 0.000000 1.089 -0.008230 0.000000 -0.007260 1992-12-11
98 364 12/18/1992 1992 12 51 18 199212 19921251 19921218 19.81 ... 0.037022 0.000000 0.038031 0.038031 0.000000 1.078 -0.010152 0.000000 -0.008230 1992-12-18
99 365 12/24/1992 1992 12 52 24 199212 19921252 19921224 19.97 ... 0.008044 0.000000 -0.007613 0.000000 -0.007613 1.074 -0.003717 0.000000 -0.010152 1992-12-24
100 366 12/31/1992 1992 12 53 31 199212 19921253 19921231 19.49 ... 0.000000 -0.024330 -0.009168 0.000000 -0.009168 1.069 -0.004666 0.000000 -0.003717 1992-12-31

53 rows × 26 columns

In [7]:
from pandas import read_csv
from pandas import DataFrame
from pandas import Grouper
from matplotlib import pyplot

groups = oil_price[['Year','oil_spot_WTI']].groupby(Grouper('Year'))
years = DataFrame()
att = []
att2 = []
plt.figure(figsize = (15,8))
for name, group in groups:
    if len(group['oil_spot_WTI'].values) == 53:
        years[name] = group['oil_spot_WTI'].values[:-1]
    elif len(group['oil_spot_WTI'].values) < 52:
        pass
    else:
        years[name] = group['oil_spot_WTI'].values
plt.style.use('seaborn-darkgrid')
years.boxplot( notch=True, patch_artist=True)
ax.grid(color='r', linestyle='-', linewidth=1)
plt.xticks(rotation = 45, fontsize = 12, weight = 'bold')
plt.yticks(fontsize = 12, weight = 'bold')
plt.xlabel("Year", fontsize = 15, weight = 'bold')
plt.ylabel("Oil spot WTI (USD/bbl)", fontsize = 15, weight = 'bold')
plt.title("Oil spot WTI (USD/bbl) since 1992", fontsize = 20, weight = 'bold', x = 0.5, y = 1.05)

plt.show()
In [8]:
from pandas import read_csv
from pandas import DataFrame
from pandas import Grouper
from matplotlib import pyplot


temp_frame = oil_price[['Year','oil_spot_WTI']]
k = np.log(temp_frame[['oil_spot_WTI']]) - np.log(temp_frame[['oil_spot_WTI']].shift(1))
temp_frame['chg_oil_spot_WTI'] = k
temp_frame.dropna(inplace = True)

groups = temp_frame[['Year','chg_oil_spot_WTI']].groupby(Grouper('Year'))
years = DataFrame()
att = []
att2 = []
plt.figure(figsize = (15,8))
for name, group in groups:
    if len(group['chg_oil_spot_WTI'].values) == 53:
        years[name] = group['chg_oil_spot_WTI'].values[:-1]
    elif len(group['chg_oil_spot_WTI'].values) < 52:
        pass
    else:
        years[name] = group['chg_oil_spot_WTI'].values
plt.style.use('seaborn-darkgrid')
years.boxplot(notch=True, patch_artist=True)
plt.xticks(rotation = 45, fontsize = 12, weight = 'bold')
plt.yticks( fontsize = 12, weight = 'bold')
plt.xlabel("Year", fontsize = 15, weight = 'bold')
plt.ylabel("Oil Spot WTI Return", fontsize = 15, weight = 'bold')
plt.ylim((-0.4,0.4))
plt.title("Return in Oil spot WTI (USD/bbl) since 1992", fontsize = 20, weight = 'bold', x = 0.5, y = 1.05)
plt.show()
C:\Users\DELL\Anaconda3\lib\site-packages\ipykernel_launcher.py:9: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  if __name__ == '__main__':
C:\Users\DELL\Anaconda3\lib\site-packages\ipykernel_launcher.py:10: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  # Remove the CWD from sys.path while we load stuff.

1.2 GDP

In [9]:
#GDP
gdp_us = pd.read_csv('GDP_US.csv')
gdp_china = pd.read_csv('GDP_China.csv')
gdp_europe = pd.read_csv('GDP_Europe.csv')
In [10]:
#Modifying GDP column names and set 'Date' as an index

gdp_yuan = gdp_china['CHNGDPNQDSMEI']
gdp_china = gdp_china.drop(columns = ('CHNGDPNQDSMEI'))
gdp_china['Chinese_yuan'] = gdp_yuan

gdp_euro = gdp_europe['CPMNACSCAB1GQEU28']
gdp_europe = gdp_europe.drop(columns = ('CPMNACSCAB1GQEU28'))
gdp_europe['Euro'] = gdp_euro


gdp_europe = gdp_europe.set_index('DATE')
gdp_us = gdp_us.set_index('DATE')
gdp_china = gdp_china.set_index('DATE')
In [11]:
#Create GDP table for analysis -- setting Par_Month as an index
import datetime

gdp_df = gdp_us.join(gdp_china).join(gdp_europe).dropna()

index_list = gdp_df.index.copy()
transform = []

for i in index_list:
    x = datetime.datetime.strptime(i, '%Y-%m-%d').strftime('%Y%m')
    transform.append(int(x))
gdp_df['gdp_date'] = gdp_df.index
gdp_df['Par_Month'] = transform
gdp_df = gdp_df.set_index('Par_Month')
gdp_df = gdp_df[['gdp_date','GDP','Chinese_yuan','Euro']].rename(columns = {"GDP" : "gdp_us", "Chinese_yuan" : "gdp_china",'Euro':'gdp_europe'})
In [12]:
gdp_df.head()
Out[12]:
gdp_date gdp_us gdp_china gdp_europe
Par_Month
199501 1995-01-01 7522.289 1.211170e+12 1811683.8
199504 1995-04-01 7580.997 1.461290e+12 1823657.0
199507 1995-07-01 7683.125 1.616410e+12 1855373.1
199510 1995-10-01 7772.586 1.845120e+12 1873811.6
199601 1996-01-01 7868.468 1.462800e+12 1895898.1
In [13]:
#Energy consumption

1.3 Global temperature

In [14]:
#Uploading Global temperature

glob_temp = pd.read_csv('Temperature_Anomalies.csv')
glob_temp = glob_temp.rename(columns = {'Year':'Par_Month'}).set_index('Par_Month')

1.4 CO2 Emission

In [15]:
co2_em = pd.read_csv('co2_emissions_by_country.csv')
co2_em_gas = pd.read_csv('co2_gaseous_emission_by_country.csv')
co2_em_liq = pd.read_csv('co2_liquid_emission_by_country.csv')
co2_em_sol = pd.read_csv('co2_solid_emission_by_country.csv')
In [16]:
def clean_em(data,region,ftype):
    data = data[data['Country Name'] == region].drop(columns = ['Country Name','Country Code','Indicator Name','Indicator Code'])
    index = data.index.values[0]
    data = np.transpose(data).rename(columns = {index : 'World_Emission' + '_' + ftype })
    data.index = data.index.astype(int)
    return data

world_co2_em = clean_em(co2_em,'World','general').dropna()
world_co2_em_gas = clean_em(co2_em_gas,'World','gas').dropna()
world_co2_em_liq = clean_em(co2_em_liq,'World','liq').dropna()
world_co2_em_sol = clean_em(co2_em_sol,'World','sol').dropna()

1.5 CO2 Concentration

In [17]:
#CO2Concentration
#Fixing -999/99 values in Carbon Dioxide concentration

co2_conc = pd.read_csv('co2_weekly_mlo.csv')
fixing_index = []
fixing_value = []
for i in range(len(co2_conc)):
    if co2_conc.iloc[i].average == -999.99:
        y = co2_conc.iloc[i].year
        a = co2_conc[(co2_conc.year == y) & (co2_conc.average != -999.99)]['average'].values.mean()
        fixing_index.append(i)
        fixing_value.append(a)
    else:
        fixing_value.append(co2_conc.iloc[i].average)
co2_conc['average'] = fixing_value
In [18]:
import datetime

#Add Par week to dataframe
def weeknumber(year,month,date):
    x = datetime.date(year,month,date).strftime("%V")
    return x

parweek = []
for i in range(len(co2_conc)):
    if int(co2_conc.iloc[i].month) < 10:
        month_dum = '0' + str(int(co2_conc.iloc[i].month))
    else:
        month_dum = str(int(co2_conc.iloc[i].month))
        
    #####################################
    
    if int(co2_conc.iloc[i].day) < 10:
        day_dum = '0' + str(int(co2_conc.iloc[i].month))
    else:
        day_dum = str(int(co2_conc.iloc[i].day))
        
    #####################################
    
    year = int(co2_conc.iloc[i].year)
    year_dum = str(year)
    month = int(month_dum)
    day = int(day_dum)
    weeknum = weeknumber(year,month,day)
    
    #####################################
    
    if int(weeknum) < 10:
        weeknum_dum = ('0' + str(int(weeknum)))
    else:
        weeknum_dum = weeknum
    
    #####################################
    
    if month_dum == '01' and weeknum_dum == '53' :
        year_dum = int(year - 1)
        month_dum = 12
    else:
        pass
    Par_week = str(year_dum) + str(month_dum) + str(weeknum_dum)
    parweek.append(Par_week)
    
#parweek
co2_conc['Par_week'] = parweek
co2_conc['Par_week'] = co2_conc['Par_week'].astype(int)

co2_conc_edited = co2_conc.groupby('Par_week').last()
#co2_conc_edited = co2_conc.set_index('Par_week').iloc[:,:5].iloc[:,4:5]
oil_price.set_index('Par_Week', inplace = True)
In [19]:
plot_seasonal_month = co2_conc.query('year >= 2005 and year < 2020 and year != 2008').groupby(['year','month']).mean()[['average']].reset_index()
plot_seasonal_month_2008_2020 = co2_conc.query('year == 2008 or year == 2020').groupby(['year','month']).mean()[['average']].reset_index()

fig, ax = plt.subplots(figsize = (4,4))

plt.style.use('seaborn-darkgrid')
#plt.style.use('ggplot')
ax1 = plot_seasonal_month.groupby('year').plot(x = 'month',y = 'average', marker = '', color = 'grey', ax = ax)
ax2 = plot_seasonal_month_2008_2020.groupby('year').plot(x = 'month',y = 'average', marker = '', color = 'red', ax = ax)

legend = plot_seasonal_month.groupby('year').mean().index
ax.legend('') #legend, loc='upper right')

plt.xlim(1,14)
plt.xticks(rotation = 45, fontsize = 10, weight = 'bold')
plt.yticks( fontsize = 10, weight = 'bold')
plt.xlabel("Month", fontsize = 10, weight = 'bold')
plt.ylabel("Carbon Dioxide Conecentration (ppm)", fontsize = 10, weight = 'bold')
plt.title("Seasonal Carbon Dioxide concentration plot", fontsize = 12, weight = 'bold', x = 0.5, y = 1.05)

#note for annotation
#for col in plot_seasonal_month.groupby('year').mean().index:
#    plt.annotate(col,xy=(plt.xticks()[0][-1]+0.7, plot_seasonal_month.groupby('year'))) #df_plot[col].iloc[-1]))
Out[19]:
Text(0.5, 1.05, 'Seasonal Carbon Dioxide concentration plot')
In [20]:
#Create Oil price to CO2 concentration tables by joining data

oil_co2_df = oil_price.join(co2_conc_edited)
oil_co2_df.head()
Out[20]:
Weekindex Date Year Month Week Day Par_Month Par_Day oil_spot_WTI oil_spot_Brent ... Date_edited year month day decimal average ndays 1_year_ago 10_years_ago increase_since_1800
Par_Week
19910205 266 2/1/1991 1991 2 5 1 199102 19910901 21.33 20.80 ... 1991-02-01 1991.0 2.0 3.0 1991.0918 355.23 7.0 354.95 340.03 74.73
19910206 267 2/8/1991 1991 2 6 8 199102 19910908 21.78 20.65 ... 1991-02-08 1991.0 2.0 10.0 1991.1110 355.79 6.0 355.09 340.74 75.12
19910207 268 2/15/1991 1991 2 7 15 199102 19910915 20.73 18.35 ... 1991-02-15 1991.0 2.0 17.0 1991.1301 356.44 6.0 355.30 340.20 75.61
19910208 269 2/22/1991 1991 2 8 22 199102 19910922 17.43 17.80 ... 1991-02-22 1991.0 2.0 24.0 1991.1493 355.73 7.0 355.02 341.52 74.72
19910309 270 3/1/1991 1991 3 9 1 199103 19910901 19.43 19.33 ... 1991-03-01 1991.0 3.0 3.0 1991.1685 357.08 6.0 355.76 341.15 75.87

5 rows × 34 columns

In [21]:
#check duplicate
oil_co2_df[oil_co2_df.Weekindex.duplicated()]
Out[21]:
Weekindex Date Year Month Week Day Par_Month Par_Day oil_spot_WTI oil_spot_Brent ... Date_edited year month day decimal average ndays 1_year_ago 10_years_ago increase_since_1800
Par_Week

0 rows × 34 columns

PACF work

In [22]:
#Using Augtolag = AIC
from statsmodels.tsa.stattools import adfuller, kpss

def adf_test(timeseries):
    print ('Results of Augmented Dickey-Fuller Test:')
    dftest = adfuller(timeseries, autolag='AIC')
    dfoutput = pd.Series(dftest[0:4], index=['Test Statistic','p-value','#Lags Used','Number of Observations Used'])
    for key,value in dftest[4].items():
       dfoutput['Critical Value (%s)'%key] = value
    print (dfoutput)
    
def kpss_test(timeseries):
    print ('Results of KPSS Test:')
    kpsstest = kpss(timeseries) #, regression='ct')
    kpss_output = pd.Series(kpsstest[0:3], index=['Test Statistic','p-value','Lags Used'])
    for key,value in kpsstest[3].items():
        kpss_output['Critical Value (%s)'%key] = value
    print (kpss_output)
In [23]:
#oil_co2_df['chg_gasoline_price'] = np.log(oil_co2_df.chg_Gasoline_price_US.shift(0)) - np.log(oil_co2_df.	chg_Gasoline_price_US.shift(1))
co2_conc_edited['chg_co2_conc'] = np.log(co2_conc_edited.average.shift(0)) - np.log(co2_conc_edited.average.shift(1))
co2_conc_edited = co2_conc_edited.dropna()
In [24]:
# Par week
import statsmodels.api as sm
#from statsmodels.tsa.arima.model import ARIMA


fig = plt.figure(figsize=(12,8))
fig.suptitle('Weekly timeframe', size = 20)
ax1 = fig.add_subplot(221)
fig = sm.graphics.tsa.plot_acf(oil_price.chg_Gasoline_price_US, lags=10, ax=ax1)
ax1.set_title('Weekly gasoline_ACF')

ax2 = fig.add_subplot(222)
fig = sm.graphics.tsa.plot_pacf(oil_price.chg_Gasoline_price_US, lags=10, ax=ax2)
ax2.set_title('Weekly gasoline_PACF')

fig = plt.figure(figsize=(12,8))
ax3 = fig.add_subplot(223)
fig = sm.graphics.tsa.plot_acf(co2_conc_edited['chg_co2_conc'], lags=10, ax=ax3)
ax3.set_title('Weekly CO2_ACF')

ax4 = fig.add_subplot(224)
fig = sm.graphics.tsa.plot_pacf(co2_conc_edited['chg_co2_conc'], lags=10, ax=ax4)
ax4.set_title('Weekly CO2_PACF')
Out[24]:
Text(0.5, 1.0, 'Weekly CO2_PACF')
In [25]:
#In papaer
# Par week
import statsmodels.api as sm
#from statsmodels.tsa.arima.model import ARIMA


fig = plt.figure(figsize=(12,8))
fig.suptitle('Weekly timeframe', size = 20)
ax1 = fig.add_subplot(221)
fig = sm.graphics.tsa.plot_acf(oil_price.chg_Gasoline_price_US, lags=10, ax=ax1)
ax1.set_title('Weekly gasoline_ACF')

fig = plt.figure(figsize=(12,8))
fig.suptitle('Weekly timeframe', size = 20)
ax1 = fig.add_subplot(222)
fig = sm.graphics.tsa.plot_acf(np.power(oil_price.chg_Gasoline_price_US,2), lags=10, ax=ax1)
ax1.set_title('Weekly gasoline ACF Squared')

fig = plt.figure(figsize=(12,8))
ax3 = fig.add_subplot(223)
fig = sm.graphics.tsa.plot_acf(co2_conc_edited['chg_co2_conc'], lags=10, ax=ax3)
ax3.set_title('Weekly CO2_ACF')

fig = plt.figure(figsize=(12,8))
ax3 = fig.add_subplot(224)
fig = sm.graphics.tsa.plot_acf(np.power(co2_conc_edited['chg_co2_conc'],2), lags=10, ax=ax3)
ax3.set_title('Weekly CO2 ACF Squared')
Out[25]:
Text(0.5, 1.0, 'Weekly CO2 ACF Squared')
In [26]:
fig = plt.figure(figsize=(8,8))

ax1 = fig.add_subplot(221)
fig = sm.graphics.tsa.plot_pacf(oil_price.chg_Gasoline_price_US, lags=10, ax=ax1)
ax1.set_title('Weekly gasoline PACF', fontsize = 12, weight = 'bold')

ax1 = fig.add_subplot(222)
fig = sm.graphics.tsa.plot_pacf(np.power(oil_price.chg_Gasoline_price_US,2), lags=10, ax=ax1)
ax1.set_title('Weekly gasoline PACF Squared', fontsize = 12, weight = 'bold')

ax3 = fig.add_subplot(223)
fig = sm.graphics.tsa.plot_pacf(co2_conc_edited['chg_co2_conc'], lags=10, ax=ax3)
ax3.set_title('Weekly CO2 PACF', fontsize = 12, weight = 'bold')

ax3 = fig.add_subplot(224)
fig = sm.graphics.tsa.plot_pacf(np.power(co2_conc_edited['chg_co2_conc'],2), lags=10, ax=ax3)
ax3.set_title('Weekly CO2 PACF Squared', fontsize = 12, weight = 'bold')
Out[26]:
Text(0.5, 1.0, 'Weekly CO2 PACF Squared')
In [27]:
print('Weekly CO2')
print(adf_test(co2_conc_edited['average']))
#print(' ')
#print(kpss_test(co2_conc_edited['average']))
Weekly CO2
Results of Augmented Dickey-Fuller Test:
Test Statistic                    0.828954
p-value                           0.992089
#Lags Used                       26.000000
Number of Observations Used    1961.000000
Critical Value (1%)              -3.433689
Critical Value (5%)              -2.863015
Critical Value (10%)             -2.567555
dtype: float64
None
In [28]:
print('Weekly Gasoline Price')
print(adf_test(oil_price.Gasoline_Price_US))
Weekly Gasoline Price
Results of Augmented Dickey-Fuller Test:
Test Statistic                   -1.943291
p-value                           0.311978
#Lags Used                       19.000000
Number of Observations Used    1546.000000
Critical Value (1%)              -3.434587
Critical Value (5%)              -2.863411
Critical Value (10%)             -2.567766
dtype: float64
None
In [29]:
print('Weekly First diff gasoline price')
print(adf_test(oil_price.chg_Gasoline_price_US))
Weekly First diff gasoline price
Results of Augmented Dickey-Fuller Test:
Test Statistic                -9.667975e+00
p-value                        1.299724e-16
#Lags Used                     2.200000e+01
Number of Observations Used    1.543000e+03
Critical Value (1%)           -3.434595e+00
Critical Value (5%)           -2.863415e+00
Critical Value (10%)          -2.567768e+00
dtype: float64
None
In [30]:
Par_month = []
for i in range(len(co2_conc)):
    if int(co2_conc.loc[i].month) < 10:
        Par_month.append(str(int(co2_conc.loc[i].year)) + str(0) + str(int(co2_conc.loc[i].month)))
    else:
        Par_month.append(str(int(co2_conc.loc[i].year)) + str(int(co2_conc.loc[i].month)))
co2_conc['Par_month'] = Par_month
co2_conc_month = co2_conc.groupby('Par_month').last()
co2_conc_month = (np.log(co2_conc_month.average.shift(0)) - np.log(co2_conc_month.average.shift(1)))
co2_conc_month = co2_conc_month.dropna()
In [31]:
#Par Month
oil_co2_month = oil_price.groupby('Par_Month').last()
gasoline_month = np.log(oil_co2_month.Gasoline_Price_US.shift(0)) - np.log(oil_co2_month.Gasoline_Price_US.shift(1))
gasoline_month = gasoline_month.dropna()
co2_conc_month

# Par week
import statsmodels.api as sm
#from statsmodels.tsa.arima.model import ARIMA

fig = plt.figure(figsize=(12,8))
fig.suptitle('Monthly timeframe', size = 20)
ax1 = fig.add_subplot(221)
fig = sm.graphics.tsa.plot_acf(gasoline_month, lags=24, ax=ax1)
ax2 = fig.add_subplot(222)
fig = sm.graphics.tsa.plot_pacf(gasoline_month, lags=24, ax=ax2)

fig = plt.figure(figsize=(12,8))
ax3 = fig.add_subplot(223)
fig = sm.graphics.tsa.plot_acf(co2_conc_month, lags=24, ax=ax3)
ax4 = fig.add_subplot(224)
fig = sm.graphics.tsa.plot_pacf(co2_conc_month, lags=24, ax=ax4)
In [32]:
print('Monthly CO2')
print(adf_test(co2_conc.groupby('Par_month').last()['average']))
Monthly CO2
Results of Augmented Dickey-Fuller Test:
Test Statistic                   3.086974
p-value                          1.000000
#Lags Used                      19.000000
Number of Observations Used    541.000000
Critical Value (1%)             -3.442495
Critical Value (5%)             -2.866897
Critical Value (10%)            -2.569623
dtype: float64
None
In [33]:
fig = plt.figure(figsize=(12,8))
fig.suptitle('Monthly CO2', size = 20)
data = co2_conc.groupby('Par_month').last()['average']
ax1 = fig.add_subplot(221)
fig = sm.graphics.tsa.plot_acf(data, lags=24, ax=ax1)
ax2 = fig.add_subplot(222)
fig = sm.graphics.tsa.plot_pacf(data, lags=24, ax=ax2)
In [34]:
print('Monthly First diff CO2')
print(adf_test(co2_conc_month))

fig = plt.figure(figsize=(12,8))
fig.suptitle('Monthly First diff CO2', size = 20)
data = co2_conc_month
ax1 = fig.add_subplot(221)
fig = sm.graphics.tsa.plot_acf(data, lags=24, ax=ax1)
ax2 = fig.add_subplot(222)
fig = sm.graphics.tsa.plot_pacf(data, lags=24, ax=ax2)
Monthly First diff CO2
Results of Augmented Dickey-Fuller Test:
Test Statistic                  -4.971689
p-value                          0.000025
#Lags Used                      18.000000
Number of Observations Used    541.000000
Critical Value (1%)             -3.442495
Critical Value (5%)             -2.866897
Critical Value (10%)            -2.569623
dtype: float64
None
In [35]:
hia_month = (co2_conc_month - co2_conc_month.shift(12))
hia_month.dropna(inplace = True)
print('Monthly first diff CO2')
print(adf_test(hia_month))

fig = plt.figure(figsize=(12,8))
fig.suptitle('Monthly First diff Seasonal CO2', size = 20)
data = hia_month
ax1 = fig.add_subplot(221)
fig = sm.graphics.tsa.plot_acf(data, lags=10, ax=ax1)
ax2 = fig.add_subplot(222)
fig = sm.graphics.tsa.plot_pacf(data, lags=10, ax=ax2)
Monthly first diff CO2
Results of Augmented Dickey-Fuller Test:
Test Statistic                -9.581761e+00
p-value                        2.149084e-16
#Lags Used                     1.400000e+01
Number of Observations Used    5.330000e+02
Critical Value (1%)           -3.442678e+00
Critical Value (5%)           -2.866978e+00
Critical Value (10%)          -2.569666e+00
dtype: float64
None
In [36]:
print('Monthly gasoline')
print(adf_test(oil_co2_df.groupby('Par_Month').last().Gasoline_Price_US))
Monthly gasoline
Results of Augmented Dickey-Fuller Test:
Test Statistic                  -1.434391
p-value                          0.565682
#Lags Used                       8.000000
Number of Observations Used    351.000000
Critical Value (1%)             -3.449119
Critical Value (5%)             -2.869810
Critical Value (10%)            -2.571176
dtype: float64
None
In [37]:
hia_gas_month = (gasoline_month - gasoline_month.shift(12))
hia_gas_month.dropna(inplace = True)

print('Monthly first diff seasonal gasoline')
print(adf_test(hia_gas_month))
Monthly first diff seasonal gasoline
Results of Augmented Dickey-Fuller Test:
Test Statistic                -8.999468e+00
p-value                        6.557010e-15
#Lags Used                     1.100000e+01
Number of Observations Used    3.350000e+02
Critical Value (1%)           -3.450022e+00
Critical Value (5%)           -2.870207e+00
Critical Value (10%)          -2.571387e+00
dtype: float64
None
In [38]:
print('Monthly first diff gasoline')
print(adf_test(gasoline_month))
Monthly first diff gasoline
Results of Augmented Dickey-Fuller Test:
Test Statistic                -6.089950e+00
p-value                        1.042278e-07
#Lags Used                     1.000000e+01
Number of Observations Used    3.480000e+02
Critical Value (1%)           -3.449282e+00
Critical Value (5%)           -2.869881e+00
Critical Value (10%)          -2.571214e+00
dtype: float64
None
In [39]:
Par_quarter = []
error = []
for i in range(len(co2_conc)):
    if (int(co2_conc.loc[i].month) >= 10 and int(co2_conc.loc[i].month) <= 12):
        Par_quarter.append(str(int(co2_conc.loc[i].year)) + str(0) + str(4))
    elif (int(co2_conc.loc[i].month) > 0 and int(co2_conc.loc[i].month) <= 3):
        Par_quarter.append(str(int(co2_conc.loc[i].year)) + str(0) + str(1))
    elif (int(co2_conc.loc[i].month) > 3 and int(co2_conc.loc[i].month) <= 6):
        Par_quarter.append(str(int(co2_conc.loc[i].year)) + str(0) + str(2))
    elif (int(co2_conc.loc[i].month) > 6 & int(co2_conc.loc[i].month) <= 9):
        Par_quarter.append(str(int(co2_conc.loc[i].year)) + str(0) + str(3))
    else:
        #print(co2_conc.loc[i])
        #error.append(co2_conc.loc[i])
        Par_quarter.append(str(int(co2_conc.loc[i].year)) + str(0) + str(999))
Par_quarter
co2_conc['Par_quarter'] = Par_quarter
co2_conc_quarter = co2_conc.groupby('Par_quarter').last()
#co2_conc_quarter
co2_conc_quarter = (np.log(co2_conc_quarter.average.shift(0)) - np.log(co2_conc_quarter.average.shift(1)))
co2_conc_quarter = co2_conc_quarter.dropna()
In [40]:
#Par Quarter

oil_co2_quarter_df = oil_price.query('Month in [12,3,6,9]') #.groupby(['Year','Month']).chg_Gasoline_price_US.last()
gas_quarter = oil_co2_quarter_df.groupby('Par_Month').Gasoline_Price_US.last()
gas_quarter = (np.log(gas_quarter.shift(0)) - np.log(gas_quarter.shift(1)))
gas_quarter = gas_quarter.dropna()

# Par week
import statsmodels.api as sm
#from statsmodels.tsa.arima.model import ARIMA

fig = plt.figure(figsize=(12,8))
fig.suptitle('Quarterly timeframe', size = 20)
ax1 = fig.add_subplot(221)
fig = sm.graphics.tsa.plot_acf(gas_quarter, lags=10, ax=ax1)
ax2 = fig.add_subplot(222)
fig = sm.graphics.tsa.plot_pacf(gas_quarter, lags=10, ax=ax2)

fig = plt.figure(figsize=(12,8))
ax3 = fig.add_subplot(223)
fig = sm.graphics.tsa.plot_acf(co2_conc_quarter, lags=10, ax=ax3)
ax4 = fig.add_subplot(224)
fig = sm.graphics.tsa.plot_pacf(co2_conc_quarter, lags=10, ax=ax4)
In [41]:
print('Quarterly CO2')
print(adf_test(co2_conc.groupby('Par_quarter').last().average))
Quarterly CO2
Results of Augmented Dickey-Fuller Test:
Test Statistic                   2.832219
p-value                          1.000000
#Lags Used                      12.000000
Number of Observations Used    175.000000
Critical Value (1%)             -3.468280
Critical Value (5%)             -2.878202
Critical Value (10%)            -2.575653
dtype: float64
None
In [42]:
fig = plt.figure(figsize=(12,8))
fig.suptitle('Quarterly CO2', size = 20)
data = co2_conc.groupby('Par_quarter').last().average
ax1 = fig.add_subplot(221)
fig = sm.graphics.tsa.plot_acf(data, lags=10, ax=ax1)
ax2 = fig.add_subplot(222)
fig = sm.graphics.tsa.plot_pacf(data, lags=10, ax=ax2)
In [43]:
print('Quarterly First diff CO2')
print(adf_test(co2_conc_quarter))
Quarterly First diff CO2
Results of Augmented Dickey-Fuller Test:
Test Statistic                  -2.711680
p-value                          0.072039
#Lags Used                      15.000000
Number of Observations Used    171.000000
Critical Value (1%)             -3.469181
Critical Value (5%)             -2.878595
Critical Value (10%)            -2.575863
dtype: float64
None
In [44]:
fig = plt.figure(figsize=(12,8))
fig.suptitle('Quarterly First diff CO2', size = 20)
data = co2_conc_quarter
ax1 = fig.add_subplot(221)
fig = sm.graphics.tsa.plot_acf(data, lags=8, ax=ax1)
ax2 = fig.add_subplot(222)
fig = sm.graphics.tsa.plot_pacf(data, lags=8, ax=ax2)
In [45]:
print('Quarterly First diff seasonal CO2')
hia_quarter = (co2_conc_quarter - co2_conc_quarter.shift(4))
hia_quarter.dropna(inplace = True)
print(adf_test(hia_quarter))

fig = plt.figure(figsize=(12,8))
fig.suptitle('Quarterly First diff Seasonal CO2', size = 20)
data = hia_quarter
ax1 = fig.add_subplot(221)
fig = sm.graphics.tsa.plot_acf(data, lags=8, ax=ax1)
ax2 = fig.add_subplot(222)
fig = sm.graphics.tsa.plot_pacf(data, lags=8, ax=ax2)
Quarterly First diff seasonal CO2
Results of Augmented Dickey-Fuller Test:
Test Statistic                -6.544822e+00
p-value                        9.154909e-09
#Lags Used                     1.100000e+01
Number of Observations Used    1.710000e+02
Critical Value (1%)           -3.469181e+00
Critical Value (5%)           -2.878595e+00
Critical Value (10%)          -2.575863e+00
dtype: float64
None
In [46]:
fig = plt.figure(figsize=(15,8))
#fig.suptitle('Monthly First diff CO2', size = 20)
#data = co2_conc_month

ax1 = fig.add_subplot(111)
fig1 = sm.graphics.tsa.plot_acf(co2_conc_month, lags=24, ax=ax1, alpha=.01)
#ax1 = fig.add_subplot(121)
fig1 = sm.graphics.tsa.plot_acf(hia_month, lags=24, ax=ax1, alpha=.01)
ax1.set_title('Autocorrelation - Monthly First Diff CO2', fontsize = 15)
#ax1.legend((l2, l4), ('oscillatory', 'damped'), loc='upper right', shadow=True)

fig2 = plt.figure(figsize=(15,8))
ax1 = fig2.add_subplot(111)
fig2 = sm.graphics.tsa.plot_acf(co2_conc_quarter, lags=24, ax=ax1, alpha=.01)
#ax1 = fig.add_subplot(121)
fig = sm.graphics.tsa.plot_acf(hia_quarter, lags=24, ax=ax1, alpha=.01)
ax1.set_title('Autocorrelation - Quarterly First Diff CO2', fontsize = 15)
Out[46]:
Text(0.5, 1.0, 'Autocorrelation - Quarterly First Diff CO2')
In [47]:
plt.style.use('seaborn-darkgrid')
fig = plt.figure(figsize=(4,4))
fig.suptitle('Autocorrelation of Carbon Dioxide \n concentration', size = 12, x= 0.5, y= 1.05, weight = 'bold')


ax1 = fig.add_subplot(221)
fig = sm.graphics.tsa.plot_acf(co2_conc_month, lags=12, ax=ax1)
ax1.set_title('First Diff CO2', fontsize = 10, weight = 'bold')
ax1.set_ylabel('Monthly', fontsize = 10, weight = 'bold')

ax2 = fig.add_subplot(222)
fig = sm.graphics.tsa.plot_acf(hia_month, lags=12, ax=ax2)
ax2.set_title('First Diff Seasonal CO2', fontsize = 10, weight = 'bold')

#fig = plt.figure(figsize=(4,4))
ax3 = fig.add_subplot(223)
fig = sm.graphics.tsa.plot_acf(co2_conc_quarter, lags=12, ax=ax3)
ax3.set_title('') #'First Diff CO2', fontsize = 10)
ax3.set_ylabel('Quarterly', fontsize = 10, weight = 'bold')


ax4 = fig.add_subplot(224)
fig = sm.graphics.tsa.plot_acf(hia_quarter, lags=12, ax=ax4)
ax4.set_title('', fontsize = 10, weight = 'bold')
ax4.set_title('') #'First Diff Seasonal CO2', fontsize = 10)
Out[47]:
Text(0.5, 1.0, '')
In [48]:
print('Quarterly Gasoline price')
print(adf_test(oil_co2_quarter_df.groupby('Par_Month').Gasoline_Price_US.last()))
Quarterly Gasoline price
Results of Augmented Dickey-Fuller Test:
Test Statistic                  -1.421096
p-value                          0.572122
#Lags Used                       3.000000
Number of Observations Used    116.000000
Critical Value (1%)             -3.488022
Critical Value (5%)             -2.886797
Critical Value (10%)            -2.580241
dtype: float64
None
In [49]:
print('Quarterly first diff Gasoline price')
print(adf_test(gas_quarter))
Quarterly first diff Gasoline price
Results of Augmented Dickey-Fuller Test:
Test Statistic                -1.105110e+01
p-value                        5.077577e-20
#Lags Used                     1.000000e+00
Number of Observations Used    1.170000e+02
Critical Value (1%)           -3.487517e+00
Critical Value (5%)           -2.886578e+00
Critical Value (10%)          -2.580124e+00
dtype: float64
None
In [50]:
hia_gas_quarter = (gas_quarter - gas_quarter.shift(4))
hia_gas_quarter.dropna(inplace = True)

print('Quarterly first diff seasonal gasoline')
print(adf_test(hia_gas_quarter))
Quarterly first diff seasonal gasoline
Results of Augmented Dickey-Fuller Test:
Test Statistic                  -4.707960
p-value                          0.000081
#Lags Used                      11.000000
Number of Observations Used    103.000000
Critical Value (1%)             -3.495493
Critical Value (5%)             -2.890037
Critical Value (10%)            -2.581971
dtype: float64
None
In [51]:
#co2_conc_quarter
Par_quarter = []
error = []
for i in range(len(co2_conc)):
    if (int(co2_conc.loc[i].month) >= 10 and int(co2_conc.loc[i].month) <= 12):
        Par_quarter.append(str(int(co2_conc.loc[i].year)) + str(0) + str(4))
    elif (int(co2_conc.loc[i].month) > 0 and int(co2_conc.loc[i].month) <= 3):
        Par_quarter.append(str(int(co2_conc.loc[i].year)) + str(0) + str(1))
    elif (int(co2_conc.loc[i].month) > 3 and int(co2_conc.loc[i].month) <= 6):
        Par_quarter.append(str(int(co2_conc.loc[i].year)) + str(0) + str(2))
    elif (int(co2_conc.loc[i].month) >= 6 & int(co2_conc.loc[i].month) <= 9):
        Par_quarter.append(str(int(co2_conc.loc[i].year)) + str(0) + str(3))
    else:
        #print(co2_conc.loc[i])
        #error.append(co2_conc.loc[i])
        Par_quarter.append(str(int(co2_conc.loc[i].year)) + str(0) + str(999))
Par_quarter
co2_conc['Par_quarter'] = Par_quarter
co2_conc_quarter = co2_conc.groupby('Par_quarter').last()

co2_conc_quarter_no_dif = co2_conc_quarter.average #(np.log(co2_conc_quarter.average.shift(0)) - np.log(co2_conc_quarter.average.shift(1)))
co2_conc_quarter_second_df = (np.log(co2_conc_quarter.average.shift(0)) - np.log(co2_conc_quarter.average.shift(1)))
co2_conc_quarter_second_df = co2_conc_quarter_second_df.shift(0) - co2_conc_quarter_second_df.shift(1)
co2_conc_quarter_second_df  = co2_conc_quarter_second_df.dropna()
In [52]:
print('Quarterly second diff seasonal CO2')
print(adf_test(co2_conc_quarter_no_dif))
Quarterly second diff seasonal CO2
Results of Augmented Dickey-Fuller Test:
Test Statistic                   2.832219
p-value                          1.000000
#Lags Used                      12.000000
Number of Observations Used    175.000000
Critical Value (1%)             -3.468280
Critical Value (5%)             -2.878202
Critical Value (10%)            -2.575653
dtype: float64
None
In [53]:
print('Quarterly second diff seasonal CO2')
print(adf_test(co2_conc_quarter_second_df))
Quarterly second diff seasonal CO2
Results of Augmented Dickey-Fuller Test:
Test Statistic                -6.502190e+00
p-value                        1.154455e-08
#Lags Used                     1.400000e+01
Number of Observations Used    1.710000e+02
Critical Value (1%)           -3.469181e+00
Critical Value (5%)           -2.878595e+00
Critical Value (10%)          -2.575863e+00
dtype: float64
None
In [54]:
sm.graphics.tsa.plot_pacf(co2_conc_quarter_second_df, lags=10, ax=ax2)
Out[54]:
In [55]:
#Par year

oil_co2_year_df = oil_price.query('Month in [12]') #.groupby(['Year','Month']).chg_Gasoline_price_US.last()
gas_year = oil_co2_year_df.groupby('Year').Gasoline_Price_US.last()
gas_year = (np.log(gas_year.shift(0)) - np.log(gas_year.shift(1)))
gas_year = gas_year.dropna()

co2_conc_year = co2_conc.groupby('year').last()
#co2_conc_quarter
co2_conc_year = (np.log(co2_conc_year.average.shift(0)) - np.log(co2_conc_year.average.shift(1)))
co2_conc_year = co2_conc_year.dropna()

# Par week
import statsmodels.api as sm
#from statsmodels.tsa.arima.model import ARIMA

fig = plt.figure(figsize=(12,8))
fig.suptitle('Yearly timeframe', size = 20)
ax1 = fig.add_subplot(221)
fig = sm.graphics.tsa.plot_acf(gas_year, lags=10, ax=ax1)
ax2 = fig.add_subplot(222)
fig = sm.graphics.tsa.plot_pacf(gas_year, lags=10, ax=ax2)

fig = plt.figure(figsize=(12,8))
ax3 = fig.add_subplot(223)
fig = sm.graphics.tsa.plot_acf(co2_conc_year, lags=10, ax=ax3)
ax4 = fig.add_subplot(224)
fig = sm.graphics.tsa.plot_pacf(co2_conc_year, lags=10, ax=ax4)
In [56]:
print('Yearly CO2')
print(adf_test(co2_conc.groupby('year').last().average))
Yearly CO2
Results of Augmented Dickey-Fuller Test:
Test Statistic                  2.904423
p-value                         1.000000
#Lags Used                      0.000000
Number of Observations Used    47.000000
Critical Value (1%)            -3.577848
Critical Value (5%)            -2.925338
Critical Value (10%)           -2.600774
dtype: float64
None
In [57]:
print('Yearly first diff CO2')
print(adf_test(co2_conc_year))
Yearly first diff CO2
Results of Augmented Dickey-Fuller Test:
Test Statistic                -6.565117e+00
p-value                        8.195750e-09
#Lags Used                     0.000000e+00
Number of Observations Used    4.600000e+01
Critical Value (1%)           -3.581258e+00
Critical Value (5%)           -2.926785e+00
Critical Value (10%)          -2.601541e+00
dtype: float64
None
In [58]:
print('Yearly Gasoline price')
print(adf_test(oil_co2_year_df.groupby('Year').Gasoline_Price_US.last()))
Yearly Gasoline price
Results of Augmented Dickey-Fuller Test:
Test Statistic                 -1.699785
p-value                         0.431223
#Lags Used                      0.000000
Number of Observations Used    29.000000
Critical Value (1%)            -3.679060
Critical Value (5%)            -2.967882
Critical Value (10%)           -2.623158
dtype: float64
None
In [59]:
print('Yearly first diff Gasoline price')
print(adf_test(gas_year))
Yearly first diff Gasoline price
Results of Augmented Dickey-Fuller Test:
Test Statistic                -6.848557e+00
p-value                        1.717621e-09
#Lags Used                     0.000000e+00
Number of Observations Used    2.800000e+01
Critical Value (1%)           -3.688926e+00
Critical Value (5%)           -2.971989e+00
Critical Value (10%)          -2.625296e+00
dtype: float64
None

2.) Test Stationary - ADF & KPSS test

In [60]:
#Using Augtolag = AIC

from statsmodels.tsa.stattools import adfuller, kpss

def adf_test(timeseries):
    print ('Results of Augmented Dickey-Fuller Test:')
    dftest = adfuller(timeseries, autolag='AIC')
    dfoutput = pd.Series(dftest[0:4], index=['Test Statistic','p-value','#Lags Used','Number of Observations Used'])
    for key,value in dftest[4].items():
       dfoutput['Critical Value (%s)'%key] = value
    print (dfoutput)
    
def kpss_test(timeseries):
    print ('Results of KPSS Test:')
    kpsstest = kpss(timeseries) #, regression='ct')
    kpss_output = pd.Series(kpsstest[0:3], index=['Test Statistic','p-value','Lags Used'])
    for key,value in kpsstest[3].items():
        kpss_output['Critical Value (%s)'%key] = value
    print (kpss_output)

2.1 Oil price -- Stationary after first difference

In [61]:
print(adf_test(oil_price['oil_spot_WTI']))
print(' ')
print(kpss_test(oil_price['oil_spot_WTI']))
Results of Augmented Dickey-Fuller Test:
Test Statistic                   -2.374022
p-value                           0.149203
#Lags Used                       10.000000
Number of Observations Used    1555.000000
Critical Value (1%)              -3.434562
Critical Value (5%)              -2.863400
Critical Value (10%)             -2.567760
dtype: float64
None
 
Results of KPSS Test:
Test Statistic            3.585767
p-value                   0.010000
Lags Used                24.000000
Critical Value (10%)      0.347000
Critical Value (5%)       0.463000
Critical Value (2.5%)     0.574000
Critical Value (1%)       0.739000
dtype: float64
None
C:\Users\DELL\Anaconda3\lib\site-packages\statsmodels\tsa\stattools.py:1276: InterpolationWarning: p-value is smaller than the indicated p-value
  warn("p-value is smaller than the indicated p-value", InterpolationWarning)
In [62]:
#Crude oil WTI_weekly
first_dif_conc = (np.log(oil_price['oil_spot_WTI'].shift(0)) - np.log(oil_price['oil_spot_WTI'].shift(1))).dropna()
print(adf_test(first_dif_conc))
print(' ')
print(kpss_test(first_dif_conc))
Results of Augmented Dickey-Fuller Test:
Test Statistic                -1.210854e+01
p-value                        1.943428e-22
#Lags Used                     1.100000e+01
Number of Observations Used    1.553000e+03
Critical Value (1%)           -3.434568e+00
Critical Value (5%)           -2.863403e+00
Critical Value (10%)          -2.567762e+00
dtype: float64
None
 
Results of KPSS Test:
Test Statistic            0.060097
p-value                   0.100000
Lags Used                24.000000
Critical Value (10%)      0.347000
Critical Value (5%)       0.463000
Critical Value (2.5%)     0.574000
Critical Value (1%)       0.739000
dtype: float64
None
C:\Users\DELL\Anaconda3\lib\site-packages\statsmodels\tsa\stattools.py:1278: InterpolationWarning: p-value is greater than the indicated p-value
  warn("p-value is greater than the indicated p-value", InterpolationWarning)
In [63]:
#Crude oil WTI Month
oil_co2_month = oil_price.groupby('Par_Month')['oil_spot_WTI'].last()

print("Crude oil WTI Month")
print(adf_test(oil_co2_month))

oil_month = np.log(oil_co2_month.shift(0)) - np.log(oil_co2_month.shift(1))
oil_month = oil_month.dropna()
print("First Diff Crude oil WTI Month")
print(adf_test(oil_month))

oil_month = oil_month - oil_month.shift(12)
oil_month = oil_month.dropna()
print("First Diff Seasonal Crude oil WTI Month")
print(adf_test(oil_month))

#Crude oil WTI Quarter

function = oil_price.query('Month in [12,3,6,9]') #.groupby(['Year','Month']).chg_Gasoline_price_US.last()
function = function.groupby('Par_Month')['oil_spot_WTI'].last()



print("Crude oil WTI Quarter")
print(adf_test(function))

function_2 = np.log(function.shift(0)) - np.log(function.shift(1))
function_2 = function_2.dropna()
print("First Diff Crude oil WTI Quarter")
print(adf_test(function_2))

function_3 = function_2 - function_2.shift(4)
function_3 = function_3.dropna()
print("First Diff Seasonal Crude oil WTI Quarter")
print(adf_test(function_3))
Crude oil WTI Month
Results of Augmented Dickey-Fuller Test:
Test Statistic                  -1.702509
p-value                          0.429820
#Lags Used                      12.000000
Number of Observations Used    347.000000
Critical Value (1%)             -3.449337
Critical Value (5%)             -2.869906
Critical Value (10%)            -2.571227
dtype: float64
None
First Diff Crude oil WTI Month
Results of Augmented Dickey-Fuller Test:
Test Statistic                -1.406313e+01
p-value                        3.031498e-26
#Lags Used                     1.000000e+00
Number of Observations Used    3.570000e+02
Critical Value (1%)           -3.448801e+00
Critical Value (5%)           -2.869670e+00
Critical Value (10%)          -2.571101e+00
dtype: float64
None
First Diff Seasonal Crude oil WTI Month
Results of Augmented Dickey-Fuller Test:
Test Statistic                -6.904563e+00
p-value                        1.256887e-09
#Lags Used                     1.300000e+01
Number of Observations Used    3.330000e+02
Critical Value (1%)           -3.450141e+00
Critical Value (5%)           -2.870259e+00
Critical Value (10%)          -2.571415e+00
dtype: float64
None
Crude oil WTI Quarter
Results of Augmented Dickey-Fuller Test:
Test Statistic                  -1.787298
p-value                          0.386786
#Lags Used                       2.000000
Number of Observations Used    117.000000
Critical Value (1%)             -3.487517
Critical Value (5%)             -2.886578
Critical Value (10%)            -2.580124
dtype: float64
None
First Diff Crude oil WTI Quarter
Results of Augmented Dickey-Fuller Test:
Test Statistic                -9.791033e+00
p-value                        6.352811e-17
#Lags Used                     1.000000e+00
Number of Observations Used    1.170000e+02
Critical Value (1%)           -3.487517e+00
Critical Value (5%)           -2.886578e+00
Critical Value (10%)          -2.580124e+00
dtype: float64
None
First Diff Seasonal Crude oil WTI Quarter
Results of Augmented Dickey-Fuller Test:
Test Statistic                  -5.228283
p-value                          0.000008
#Lags Used                      11.000000
Number of Observations Used    103.000000
Critical Value (1%)             -3.495493
Critical Value (5%)             -2.890037
Critical Value (10%)            -2.581971
dtype: float64
None
In [64]:
#Crude oil WTI Month
#Change this line and title
index = 'oil_spot_Brent'
oil_co2_month = oil_price.groupby('Par_Month')[index].last()

print("Crude oil Brent Month")
print(adf_test(oil_co2_month))

oil_month = np.log(oil_co2_month.shift(0)) - np.log(oil_co2_month.shift(1))
oil_month = oil_month.dropna()
print("First Diff Crude oil Brent Month")
print(adf_test(oil_month))

oil_month = oil_month - oil_month.shift(12)
oil_month = oil_month.dropna()
print("First Diff Seasonal Crude oil WTI Month")
print(adf_test(oil_month))

#Crude oil WTI Quarter

function = oil_price.query('Month in [12,3,6,9]') #.groupby(['Year','Month']).chg_Gasoline_price_US.last()
function = function.groupby('Par_Month')[index].last()



print("Crude oil Brent Quarter")
print(adf_test(function))

function_2 = np.log(function.shift(0)) - np.log(function.shift(1))
function_2 = function_2.dropna()
print("First Diff Crude oil Brent Quarter")
print(adf_test(function_2))

function_3 = function_2 - function_2.shift(4)
function_3 = function_3.dropna()
print("First Diff Seasonal Crude oil Brent Quarter")
print(adf_test(function_3))
Crude oil Brent Month
Results of Augmented Dickey-Fuller Test:
Test Statistic                  -2.144924
p-value                          0.226838
#Lags Used                       1.000000
Number of Observations Used    358.000000
Critical Value (1%)             -3.448749
Critical Value (5%)             -2.869647
Critical Value (10%)            -2.571089
dtype: float64
None
First Diff Crude oil Brent Month
Results of Augmented Dickey-Fuller Test:
Test Statistic                -1.779196e+01
p-value                        3.244454e-30
#Lags Used                     0.000000e+00
Number of Observations Used    3.580000e+02
Critical Value (1%)           -3.448749e+00
Critical Value (5%)           -2.869647e+00
Critical Value (10%)          -2.571089e+00
dtype: float64
None
First Diff Seasonal Crude oil WTI Month
Results of Augmented Dickey-Fuller Test:
Test Statistic                -8.269647e+00
p-value                        4.831940e-13
#Lags Used                     1.200000e+01
Number of Observations Used    3.340000e+02
Critical Value (1%)           -3.450081e+00
Critical Value (5%)           -2.870233e+00
Critical Value (10%)          -2.571401e+00
dtype: float64
None
Crude oil Brent Quarter
Results of Augmented Dickey-Fuller Test:
Test Statistic                  -2.213187
p-value                          0.201494
#Lags Used                       0.000000
Number of Observations Used    119.000000
Critical Value (1%)             -3.486535
Critical Value (5%)             -2.886151
Critical Value (10%)            -2.579896
dtype: float64
None
First Diff Crude oil Brent Quarter
Results of Augmented Dickey-Fuller Test:
Test Statistic                -9.520671e+00
p-value                        3.071004e-16
#Lags Used                     1.000000e+00
Number of Observations Used    1.170000e+02
Critical Value (1%)           -3.487517e+00
Critical Value (5%)           -2.886578e+00
Critical Value (10%)          -2.580124e+00
dtype: float64
None
First Diff Seasonal Crude oil Brent Quarter
Results of Augmented Dickey-Fuller Test:
Test Statistic                  -4.846833
p-value                          0.000044
#Lags Used                      11.000000
Number of Observations Used    103.000000
Critical Value (1%)             -3.495493
Critical Value (5%)             -2.890037
Critical Value (10%)            -2.581971
dtype: float64
None
In [65]:
print(adf_test(oil_price['future_oil_contract_1']))
Results of Augmented Dickey-Fuller Test:
Test Statistic                   -2.360710
p-value                           0.153134
#Lags Used                       10.000000
Number of Observations Used    1555.000000
Critical Value (1%)              -3.434562
Critical Value (5%)              -2.863400
Critical Value (10%)             -2.567760
dtype: float64
None
In [66]:
first_dif_conc = (np.log(oil_price['future_oil_contract_1'].shift(0)) - np.log(oil_price['future_oil_contract_1'].shift(1))).dropna()
print(adf_test(first_dif_conc))
Results of Augmented Dickey-Fuller Test:
Test Statistic                -1.090610e+01
p-value                        1.127165e-19
#Lags Used                     1.300000e+01
Number of Observations Used    1.551000e+03
Critical Value (1%)           -3.434573e+00
Critical Value (5%)           -2.863405e+00
Critical Value (10%)          -2.567763e+00
dtype: float64
None
In [67]:
#Crude oil WTI Month
#Change this line and title
index = 'future_oil_contract_1'
oil_co2_month = oil_price.groupby('Par_Month')[index].last()

print(index +" Month")
print(adf_test(oil_co2_month))

oil_month = np.log(oil_co2_month.shift(0)) - np.log(oil_co2_month.shift(1))
oil_month = oil_month.dropna()
print("First Diff " + index + " Month")
print(adf_test(oil_month))

oil_month = oil_month - oil_month.shift(12)
oil_month = oil_month.dropna()
print("First Diff Seasonal "+index+" Month")
print(adf_test(oil_month))

#Crude oil WTI Quarter

function = oil_price.query('Month in [12,3,6,9]') #.groupby(['Year','Month']).chg_Gasoline_price_US.last()
function = function.groupby('Par_Month')[index].last()



print(index + " Quarter")
print(adf_test(function))

function_2 = np.log(function.shift(0)) - np.log(function.shift(1))
function_2 = function_2.dropna()
print("First Diff "+index+" Quarter")
print(adf_test(function_2))

function_3 = function_2 - function_2.shift(4)
function_3 = function_3.dropna()
print("First Diff Seasonal "+index +" Quarter")
print(adf_test(function_3))
future_oil_contract_1 Month
Results of Augmented Dickey-Fuller Test:
Test Statistic                  -1.686470
p-value                          0.438096
#Lags Used                      12.000000
Number of Observations Used    347.000000
Critical Value (1%)             -3.449337
Critical Value (5%)             -2.869906
Critical Value (10%)            -2.571227
dtype: float64
None
First Diff future_oil_contract_1 Month
Results of Augmented Dickey-Fuller Test:
Test Statistic                -1.727792e+01
p-value                        5.806193e-30
#Lags Used                     0.000000e+00
Number of Observations Used    3.580000e+02
Critical Value (1%)           -3.448749e+00
Critical Value (5%)           -2.869647e+00
Critical Value (10%)          -2.571089e+00
dtype: float64
None
First Diff Seasonal future_oil_contract_1 Month
Results of Augmented Dickey-Fuller Test:
Test Statistic                -6.940285e+00
p-value                        1.029301e-09
#Lags Used                     1.300000e+01
Number of Observations Used    3.330000e+02
Critical Value (1%)           -3.450141e+00
Critical Value (5%)           -2.870259e+00
Critical Value (10%)          -2.571415e+00
dtype: float64
None
future_oil_contract_1 Quarter
Results of Augmented Dickey-Fuller Test:
Test Statistic                  -1.764842
p-value                          0.398051
#Lags Used                       2.000000
Number of Observations Used    117.000000
Critical Value (1%)             -3.487517
Critical Value (5%)             -2.886578
Critical Value (10%)            -2.580124
dtype: float64
None
First Diff future_oil_contract_1 Quarter
Results of Augmented Dickey-Fuller Test:
Test Statistic                -9.535318e+00
p-value                        2.818976e-16
#Lags Used                     1.000000e+00
Number of Observations Used    1.170000e+02
Critical Value (1%)           -3.487517e+00
Critical Value (5%)           -2.886578e+00
Critical Value (10%)          -2.580124e+00
dtype: float64
None
First Diff Seasonal future_oil_contract_1 Quarter
Results of Augmented Dickey-Fuller Test:
Test Statistic                  -5.251882
p-value                          0.000007
#Lags Used                      11.000000
Number of Observations Used    103.000000
Critical Value (1%)             -3.495493
Critical Value (5%)             -2.890037
Critical Value (10%)            -2.581971
dtype: float64
None
In [68]:
print(adf_test(oil_price['sugar_price_us']))
Results of Augmented Dickey-Fuller Test:
Test Statistic                   -2.568984
p-value                           0.099578
#Lags Used                       11.000000
Number of Observations Used    1554.000000
Critical Value (1%)              -3.434565
Critical Value (5%)              -2.863402
Critical Value (10%)             -2.567761
dtype: float64
None
In [69]:
#Sugar price week
first_dif_conc = (np.log(oil_price['sugar_price_us'].shift(0)) - np.log(oil_price['sugar_price_us'].shift(1))).dropna()
print(adf_test(first_dif_conc))
Results of Augmented Dickey-Fuller Test:
Test Statistic                  -21.905431
p-value                           0.000000
#Lags Used                        2.000000
Number of Observations Used    1562.000000
Critical Value (1%)              -3.434543
Critical Value (5%)              -2.863392
Critical Value (10%)             -2.567756
dtype: float64
None
In [70]:
#Crude oil WTI Month
#Change this line and title
index = 'sugar_price_us'
oil_co2_month = oil_price.groupby('Par_Month')[index].last()

print(index +" Month")
print(adf_test(oil_co2_month))

oil_month = np.log(oil_co2_month.shift(0)) - np.log(oil_co2_month.shift(1))
oil_month = oil_month.dropna()
print("First Diff " + index + " Month")
print(adf_test(oil_month))

oil_month = oil_month - oil_month.shift(12)
oil_month = oil_month.dropna()
print("First Diff "+index+" Month")
print(adf_test(oil_month))

#Crude oil WTI Quarter

function = oil_price.query('Month in [12,3,6,9]') #.groupby(['Year','Month']).chg_Gasoline_price_US.last()
function = function.groupby('Par_Month')[index].last()



print(index + " Quarter")
print(adf_test(function))

function_2 = np.log(function.shift(0)) - np.log(function.shift(1))
function_2 = function_2.dropna()
print("First Diff "+index+" Quarter")
print(adf_test(function_2))

function_3 = function_2 - function_2.shift(4)
function_3 = function_3.dropna()
print("First Diff Seasonal "+index +" Quarter")
print(adf_test(function_3))
sugar_price_us Month
Results of Augmented Dickey-Fuller Test:
Test Statistic                  -2.002643
p-value                          0.285415
#Lags Used                      11.000000
Number of Observations Used    348.000000
Critical Value (1%)             -3.449282
Critical Value (5%)             -2.869881
Critical Value (10%)            -2.571214
dtype: float64
None
First Diff sugar_price_us Month
Results of Augmented Dickey-Fuller Test:
Test Statistic                -1.595694e+01
p-value                        7.250537e-29
#Lags Used                     0.000000e+00
Number of Observations Used    3.580000e+02
Critical Value (1%)           -3.448749e+00
Critical Value (5%)           -2.869647e+00
Critical Value (10%)          -2.571089e+00
dtype: float64
None
First Diff sugar_price_us Month
Results of Augmented Dickey-Fuller Test:
Test Statistic                -9.566867e+00
p-value                        2.344389e-16
#Lags Used                     1.100000e+01
Number of Observations Used    3.350000e+02
Critical Value (1%)           -3.450022e+00
Critical Value (5%)           -2.870207e+00
Critical Value (10%)          -2.571387e+00
dtype: float64
None
sugar_price_us Quarter
Results of Augmented Dickey-Fuller Test:
Test Statistic                  -2.057163
p-value                          0.262084
#Lags Used                       2.000000
Number of Observations Used    117.000000
Critical Value (1%)             -3.487517
Critical Value (5%)             -2.886578
Critical Value (10%)            -2.580124
dtype: float64
None
First Diff sugar_price_us Quarter
Results of Augmented Dickey-Fuller Test:
Test Statistic                -1.058403e+01
p-value                        6.789470e-19
#Lags Used                     0.000000e+00
Number of Observations Used    1.180000e+02
Critical Value (1%)           -3.487022e+00
Critical Value (5%)           -2.886363e+00
Critical Value (10%)          -2.580009e+00
dtype: float64
None
First Diff Seasonal sugar_price_us Quarter
Results of Augmented Dickey-Fuller Test:
Test Statistic                -6.866344e+00
p-value                        1.555622e-09
#Lags Used                     7.000000e+00
Number of Observations Used    1.070000e+02
Critical Value (1%)           -3.492996e+00
Critical Value (5%)           -2.888955e+00
Critical Value (10%)          -2.581393e+00
dtype: float64
None
In [71]:
#Sugar price month
oil_co2_month = oil_co2_df.groupby('Par_Month').last()
sugar_month = np.log(oil_co2_month.sugar_price_us.shift(0)) - np.log(oil_co2_month.sugar_price_us.shift(1))
gasoline_month = gasoline_month.dropna()
In [72]:
print(adf_test(oil_price['ethanol_price_us'].dropna()))
Results of Augmented Dickey-Fuller Test:
Test Statistic                  -3.260984
p-value                          0.016715
#Lags Used                       1.000000
Number of Observations Used    823.000000
Critical Value (1%)             -3.438321
Critical Value (5%)             -2.865058
Critical Value (10%)            -2.568643
dtype: float64
None
In [73]:
first_dif_conc = (np.log(oil_price['ethanol_price_us'].dropna().shift(0)) - np.log(oil_price['ethanol_price_us'].dropna().shift(1))).dropna()
print(adf_test(first_dif_conc))
Results of Augmented Dickey-Fuller Test:
Test Statistic                 -27.800636
p-value                          0.000000
#Lags Used                       0.000000
Number of Observations Used    823.000000
Critical Value (1%)             -3.438321
Critical Value (5%)             -2.865058
Critical Value (10%)            -2.568643
dtype: float64
None
In [74]:
#Crude oil WTI Month
#Change this line and title
index = 'ethanol_price_us'
oil_co2_month = oil_price.groupby('Par_Month')[index].last()
oil_co2_month.dropna(inplace = True)

print(index +" Month")
print(adf_test(oil_co2_month))

oil_month = np.log(oil_co2_month.shift(0)) - np.log(oil_co2_month.shift(1))
oil_month = oil_month.dropna()
print("First Diff " + index + " Month")
print(adf_test(oil_month))

oil_month = oil_month - oil_month.shift(12)
oil_month = oil_month.dropna()
print("First Diff "+index+" Month")
print(adf_test(oil_month))

#Crude oil WTI Quarter

function = oil_price.query('Month in [12,3,6,9]') #.groupby(['Year','Month']).chg_Gasoline_price_US.last()
function = function.groupby('Par_Month')[index].last()
function.dropna(inplace = True)

print(index + " Quarter")
print(adf_test(function))

function_2 = np.log(function.shift(0)) - np.log(function.shift(1))
function_2 = function_2.dropna()
print("First Diff "+index+" Quarter")
print(adf_test(function_2))

function_3 = function_2 - function_2.shift(4)
function_3 = function_3.dropna()
print("First Diff Seasonal "+index +" Quarter")
print(adf_test(function_3))
ethanol_price_us Month
Results of Augmented Dickey-Fuller Test:
Test Statistic                  -3.129073
p-value                          0.024475
#Lags Used                       1.000000
Number of Observations Used    188.000000
Critical Value (1%)             -3.465620
Critical Value (5%)             -2.877040
Critical Value (10%)            -2.575032
dtype: float64
None
First Diff ethanol_price_us Month
Results of Augmented Dickey-Fuller Test:
Test Statistic                -1.395732e+01
p-value                        4.586363e-26
#Lags Used                     0.000000e+00
Number of Observations Used    1.880000e+02
Critical Value (1%)           -3.465620e+00
Critical Value (5%)           -2.877040e+00
Critical Value (10%)          -2.575032e+00
dtype: float64
None
First Diff ethanol_price_us Month
Results of Augmented Dickey-Fuller Test:
Test Statistic                -6.452678e+00
p-value                        1.509847e-08
#Lags Used                     1.200000e+01
Number of Observations Used    1.640000e+02
Critical Value (1%)           -3.470866e+00
Critical Value (5%)           -2.879330e+00
Critical Value (10%)          -2.576255e+00
dtype: float64
None
ethanol_price_us Quarter
Results of Augmented Dickey-Fuller Test:
Test Statistic                 -3.642951
p-value                         0.004991
#Lags Used                      0.000000
Number of Observations Used    62.000000
Critical Value (1%)            -3.540523
Critical Value (5%)            -2.909427
Critical Value (10%)           -2.592314
dtype: float64
None
First Diff ethanol_price_us Quarter
Results of Augmented Dickey-Fuller Test:
Test Statistic                -7.478585e+00
p-value                        4.839526e-11
#Lags Used                     1.000000e+00
Number of Observations Used    6.000000e+01
Critical Value (1%)           -3.544369e+00
Critical Value (5%)           -2.911073e+00
Critical Value (10%)          -2.593190e+00
dtype: float64
None
First Diff Seasonal ethanol_price_us Quarter
Results of Augmented Dickey-Fuller Test:
Test Statistic                 -4.266035
p-value                         0.000508
#Lags Used                      9.000000
Number of Observations Used    48.000000
Critical Value (1%)            -3.574589
Critical Value (5%)            -2.923954
Critical Value (10%)           -2.600039
dtype: float64
None

2.2 GDP -- Stationary after first difference

In [75]:
class color:
   PURPLE = '\033[95m'
   CYAN = '\033[96m'
   DARKCYAN = '\033[36m'
   BLUE = '\033[94m'
   GREEN = '\033[92m'
   YELLOW = '\033[93m'
   RED = '\033[91m'
   BOLD = '\033[1m'
   UNDERLINE = '\033[4m'
   END = '\033[0m'
In [76]:
print(color.BOLD +'GDP_US' + color.END)
print(adf_test(gdp_df['gdp_us']))
print(' ')
print(kpss_test(gdp_df['gdp_us']))

print(color.BOLD +'GDP_China' + color.END)
print(adf_test(gdp_df['gdp_china']))
print(' ')
print(kpss_test(gdp_df['gdp_china']))

print(color.BOLD +'GDP_Europe' + color.END)
print(adf_test(gdp_df['gdp_europe']))
print(' ')
print(kpss_test(gdp_df['gdp_europe']))
GDP_US
Results of Augmented Dickey-Fuller Test:
Test Statistic                  1.495677
p-value                         0.997508
#Lags Used                      1.000000
Number of Observations Used    98.000000
Critical Value (1%)            -3.498910
Critical Value (5%)            -2.891516
Critical Value (10%)           -2.582760
dtype: float64
None
 
Results of KPSS Test:
Test Statistic            0.880981
p-value                   0.010000
Lags Used                12.000000
Critical Value (10%)      0.347000
Critical Value (5%)       0.463000
Critical Value (2.5%)     0.574000
Critical Value (1%)       0.739000
dtype: float64
None
GDP_China
Results of Augmented Dickey-Fuller Test:
Test Statistic                  0.998199
p-value                         0.994247
#Lags Used                     12.000000
Number of Observations Used    87.000000
Critical Value (1%)            -3.507853
Critical Value (5%)            -2.895382
Critical Value (10%)           -2.584824
dtype: float64
None
 
Results of KPSS Test:
Test Statistic            0.837875
p-value                   0.010000
Lags Used                12.000000
Critical Value (10%)      0.347000
Critical Value (5%)       0.463000
Critical Value (2.5%)     0.574000
Critical Value (1%)       0.739000
dtype: float64
None
GDP_Europe
Results of Augmented Dickey-Fuller Test:
Test Statistic                 -0.369173
p-value                         0.915120
#Lags Used                      1.000000
Number of Observations Used    98.000000
Critical Value (1%)            -3.498910
Critical Value (5%)            -2.891516
Critical Value (10%)           -2.582760
dtype: float64
None
 
Results of KPSS Test:
Test Statistic            0.874584
p-value                   0.010000
Lags Used                12.000000
Critical Value (10%)      0.347000
Critical Value (5%)       0.463000
Critical Value (2.5%)     0.574000
Critical Value (1%)       0.739000
dtype: float64
None
C:\Users\DELL\Anaconda3\lib\site-packages\statsmodels\tsa\stattools.py:1276: InterpolationWarning: p-value is smaller than the indicated p-value
  warn("p-value is smaller than the indicated p-value", InterpolationWarning)
C:\Users\DELL\Anaconda3\lib\site-packages\statsmodels\tsa\stattools.py:1276: InterpolationWarning: p-value is smaller than the indicated p-value
  warn("p-value is smaller than the indicated p-value", InterpolationWarning)
C:\Users\DELL\Anaconda3\lib\site-packages\statsmodels\tsa\stattools.py:1276: InterpolationWarning: p-value is smaller than the indicated p-value
  warn("p-value is smaller than the indicated p-value", InterpolationWarning)
In [77]:
first_dif_gdp = (np.log(gdp_df[['gdp_us','gdp_china','gdp_europe']].shift(0)) - np.log(gdp_df[['gdp_us','gdp_china','gdp_europe']].shift(1))).dropna()
In [78]:
print(color.BOLD +'GDP_US' + color.END)
print(adf_test(first_dif_gdp['gdp_us']))
print(' ')
print(kpss_test(first_dif_gdp['gdp_us']))

print(color.BOLD +'GDP_China' + color.END)
print(adf_test(first_dif_gdp['gdp_china']))
print(' ')
print(kpss_test(first_dif_gdp['gdp_china']))

print(color.BOLD +'GDP_Europe' + color.END)
print(adf_test(first_dif_gdp['gdp_europe']))
print(' ')
print(kpss_test(first_dif_gdp['gdp_europe']))
GDP_US
Results of Augmented Dickey-Fuller Test:
Test Statistic                 -4.058266
p-value                         0.001134
#Lags Used                      1.000000
Number of Observations Used    97.000000
Critical Value (1%)            -3.499637
Critical Value (5%)            -2.891831
Critical Value (10%)           -2.582928
dtype: float64
None
 
Results of KPSS Test:
Test Statistic            0.25672
p-value                   0.10000
Lags Used                12.00000
Critical Value (10%)      0.34700
Critical Value (5%)       0.46300
Critical Value (2.5%)     0.57400
Critical Value (1%)       0.73900
dtype: float64
None
GDP_China
Results of Augmented Dickey-Fuller Test:
Test Statistic                 -2.963546
p-value                         0.038442
#Lags Used                      4.000000
Number of Observations Used    94.000000
Critical Value (1%)            -3.501912
Critical Value (5%)            -2.892815
Critical Value (10%)           -2.583454
dtype: float64
None
 
Results of KPSS Test:
Test Statistic            0.10028
p-value                   0.10000
Lags Used                12.00000
Critical Value (10%)      0.34700
Critical Value (5%)       0.46300
Critical Value (2.5%)     0.57400
Critical Value (1%)       0.73900
dtype: float64
None
GDP_Europe
Results of Augmented Dickey-Fuller Test:
Test Statistic                -5.708235e+00
p-value                        7.402388e-07
#Lags Used                     0.000000e+00
Number of Observations Used    9.800000e+01
Critical Value (1%)           -3.498910e+00
Critical Value (5%)           -2.891516e+00
Critical Value (10%)          -2.582760e+00
dtype: float64
None
 
Results of KPSS Test:
Test Statistic            0.328955
p-value                   0.100000
Lags Used                12.000000
Critical Value (10%)      0.347000
Critical Value (5%)       0.463000
Critical Value (2.5%)     0.574000
Critical Value (1%)       0.739000
dtype: float64
None
C:\Users\DELL\Anaconda3\lib\site-packages\statsmodels\tsa\stattools.py:1278: InterpolationWarning: p-value is greater than the indicated p-value
  warn("p-value is greater than the indicated p-value", InterpolationWarning)
C:\Users\DELL\Anaconda3\lib\site-packages\statsmodels\tsa\stattools.py:1278: InterpolationWarning: p-value is greater than the indicated p-value
  warn("p-value is greater than the indicated p-value", InterpolationWarning)
C:\Users\DELL\Anaconda3\lib\site-packages\statsmodels\tsa\stattools.py:1278: InterpolationWarning: p-value is greater than the indicated p-value
  warn("p-value is greater than the indicated p-value", InterpolationWarning)
In [79]:
(first_dif_gdp.shift(0)) - first_dif_gdp.shift(4)
Out[79]:
gdp_us gdp_china gdp_europe
Par_Month
199504 NaN NaN NaN
199507 NaN NaN NaN
199510 NaN NaN NaN
199601 NaN NaN NaN
199604 0.012901 -0.028818 0.010418
... ... ... ...
201810 -0.008189 -0.004386 -0.002861
201901 -0.005367 -0.005715 0.006238
201904 -0.005109 -0.012740 -0.002534
201907 0.000613 -0.006918 -0.000936
201910 0.001542 -0.001309 0.002807

99 rows × 3 columns

In [80]:
#First diff seasonal GDP

first_dif_seasonal_gdp = (first_dif_gdp.shift(0)) - first_dif_gdp.shift(4)
first_dif_seasonal_gdp.dropna(inplace = True)

print(color.BOLD +'GDP_US' + color.END)
print(adf_test(first_dif_seasonal_gdp['gdp_us']))
print(' ')
print(kpss_test(first_dif_seasonal_gdp['gdp_us']))

print(color.BOLD +'GDP_China' + color.END)
print(adf_test(first_dif_seasonal_gdp['gdp_china']))
print(' ')
print(kpss_test(first_dif_seasonal_gdp['gdp_china']))

print(color.BOLD +'GDP_Europe' + color.END)
print(adf_test(first_dif_seasonal_gdp['gdp_europe']))
print(' ')
print(kpss_test(first_dif_seasonal_gdp['gdp_europe']))
GDP_US
Results of Augmented Dickey-Fuller Test:
Test Statistic                 -2.875271
p-value                         0.048300
#Lags Used                     12.000000
Number of Observations Used    82.000000
Critical Value (1%)            -3.512738
Critical Value (5%)            -2.897490
Critical Value (10%)           -2.585949
dtype: float64
None
 
Results of KPSS Test:
Test Statistic            0.057557
p-value                   0.100000
Lags Used                12.000000
Critical Value (10%)      0.347000
Critical Value (5%)       0.463000
Critical Value (2.5%)     0.574000
Critical Value (1%)       0.739000
dtype: float64
None
GDP_China
Results of Augmented Dickey-Fuller Test:
Test Statistic                 -5.221257
p-value                         0.000008
#Lags Used                      6.000000
Number of Observations Used    88.000000
Critical Value (1%)            -3.506944
Critical Value (5%)            -2.894990
Critical Value (10%)           -2.584615
dtype: float64
None
 
Results of KPSS Test:
Test Statistic            0.114921
p-value                   0.100000
Lags Used                12.000000
Critical Value (10%)      0.347000
Critical Value (5%)       0.463000
Critical Value (2.5%)     0.574000
Critical Value (1%)       0.739000
dtype: float64
None
GDP_Europe
Results of Augmented Dickey-Fuller Test:
Test Statistic                 -5.048193
p-value                         0.000018
#Lags Used                     11.000000
Number of Observations Used    83.000000
Critical Value (1%)            -3.511712
Critical Value (5%)            -2.897048
Critical Value (10%)           -2.585713
dtype: float64
None
 
Results of KPSS Test:
Test Statistic            0.071891
p-value                   0.100000
Lags Used                12.000000
Critical Value (10%)      0.347000
Critical Value (5%)       0.463000
Critical Value (2.5%)     0.574000
Critical Value (1%)       0.739000
dtype: float64
None
C:\Users\DELL\Anaconda3\lib\site-packages\statsmodels\tsa\stattools.py:1278: InterpolationWarning: p-value is greater than the indicated p-value
  warn("p-value is greater than the indicated p-value", InterpolationWarning)
C:\Users\DELL\Anaconda3\lib\site-packages\statsmodels\tsa\stattools.py:1278: InterpolationWarning: p-value is greater than the indicated p-value
  warn("p-value is greater than the indicated p-value", InterpolationWarning)
C:\Users\DELL\Anaconda3\lib\site-packages\statsmodels\tsa\stattools.py:1278: InterpolationWarning: p-value is greater than the indicated p-value
  warn("p-value is greater than the indicated p-value", InterpolationWarning)
In [81]:
#GDP weekly
#oil_price.join
In [82]:
gdp_date_list = gdp_df.gdp_date.to_list()
year = []
month = []
quarter = []
weeknum = []
for i in range(len(gdp_date_list)):
    if int(datetime.datetime.strptime(gdp_date_list[i],'%Y-%m-%d').strftime('%m')) == 1:
        y = int(datetime.datetime.strptime(gdp_date_list[i],'%Y-%m-%d').strftime('%Y'))-1
        m = int(12)
        d = int(4)
        year.append(y)
        month.append(m)
        quarter.append(d)
    else:
        y = int(datetime.datetime.strptime(gdp_date_list[i],'%Y-%m-%d').strftime('%Y'))
        m = int(datetime.datetime.strptime(gdp_date_list[i],'%Y-%m-%d').strftime('%m'))-1
        d = int(datetime.datetime.strptime(gdp_date_list[i],'%Y-%m-%d').strftime('%m'))//3
        year.append(y)
        month.append(m)
        quarter.append(d)
gdp_df['Year'] = year
gdp_df['Month'] = month
gdp_df['Quarter'] = quarter
In [83]:
gdp_df.head()
Out[83]:
gdp_date gdp_us gdp_china gdp_europe Year Month Quarter
Par_Month
199501 1995-01-01 7522.289 1.211170e+12 1811683.8 1994 12 4
199504 1995-04-01 7580.997 1.461290e+12 1823657.0 1995 3 1
199507 1995-07-01 7683.125 1.616410e+12 1855373.1 1995 6 2
199510 1995-10-01 7772.586 1.845120e+12 1873811.6 1995 9 3
199601 1996-01-01 7868.468 1.462800e+12 1895898.1 1995 12 4
In [84]:
oil_price_month = oil_price['Month'].to_list()
quarter = []
for i in range(len(oil_price_month)):
    if oil_price_month[i] in [1,2,3]:
        #print(oil_price_month[i])
        quarter.append(1)
    elif oil_price_month[i] in [4,5,6]:
        quarter.append(2)
    elif oil_price_month[i] in [7,8,9]:
        quarter.append(3)
    elif oil_price_month[i] in [10,11,12]:
        quarter.append(4)
    else:
        quarter.append(oil_price_month[i])
        
oil_price['Quarter'] = quarter
In [85]:
test_stationary_gdp_weekly = pd.merge(oil_price, gdp_df, how="left", on=['Year','Quarter']).drop(columns = ['Month_y']).rename(columns = {'Month_x':'Month'}).set_index('Par_Month') #.to_csv('quick_look_gdp_week1.csv')
In [86]:
test_stationary_gdp_weekly = test_stationary_gdp_weekly.dropna(subset = ['gdp_date'])[['gdp_china','gdp_us','gdp_europe']]
In [87]:
print(color.BOLD +'GDP_US' + color.END)
print(adf_test(test_stationary_gdp_weekly['gdp_us']))

print(color.BOLD +'GDP_China' + color.END)
print(adf_test(test_stationary_gdp_weekly['gdp_china']))

print(color.BOLD +'GDP_Europe' + color.END)
print(adf_test(test_stationary_gdp_weekly['gdp_europe']))
GDP_US
Results of Augmented Dickey-Fuller Test:
Test Statistic                    1.457719
p-value                           0.997361
#Lags Used                       14.000000
Number of Observations Used    1289.000000
Critical Value (1%)              -3.435433
Critical Value (5%)              -2.863785
Critical Value (10%)             -2.567965
dtype: float64
None
GDP_China
Results of Augmented Dickey-Fuller Test:
Test Statistic                    1.732468
p-value                           0.998205
#Lags Used                       14.000000
Number of Observations Used    1289.000000
Critical Value (1%)              -3.435433
Critical Value (5%)              -2.863785
Critical Value (10%)             -2.567965
dtype: float64
None
GDP_Europe
Results of Augmented Dickey-Fuller Test:
Test Statistic                   -0.357654
p-value                           0.916933
#Lags Used                       14.000000
Number of Observations Used    1289.000000
Critical Value (1%)              -3.435433
Critical Value (5%)              -2.863785
Critical Value (10%)             -2.567965
dtype: float64
None
In [88]:
first_dif_gdp_weekly = (np.log(test_stationary_gdp_weekly[['gdp_us','gdp_china','gdp_europe']].shift(0)) - np.log(test_stationary_gdp_weekly[['gdp_us','gdp_china','gdp_europe']].shift(1))).dropna()
In [89]:
print(color.BOLD +'GDP_US' + color.END)
print(adf_test(first_dif_gdp_weekly['gdp_us']))


print(color.BOLD +'GDP_China' + color.END)
print(adf_test(first_dif_gdp_weekly['gdp_china']))


print(color.BOLD +'GDP_Europe' + color.END)
print(adf_test(first_dif_gdp_weekly['gdp_europe']))
GDP_US
Results of Augmented Dickey-Fuller Test:
Test Statistic                   -5.571394
p-value                           0.000001
#Lags Used                       14.000000
Number of Observations Used    1288.000000
Critical Value (1%)              -3.435437
Critical Value (5%)              -2.863787
Critical Value (10%)             -2.567966
dtype: float64
None
GDP_China
Results of Augmented Dickey-Fuller Test:
Test Statistic                -1.461636e+01
p-value                        3.948440e-27
#Lags Used                     1.300000e+01
Number of Observations Used    1.289000e+03
Critical Value (1%)           -3.435433e+00
Critical Value (5%)           -2.863785e+00
Critical Value (10%)          -2.567965e+00
dtype: float64
None
GDP_Europe
Results of Augmented Dickey-Fuller Test:
Test Statistic                   -5.522921
p-value                           0.000002
#Lags Used                       13.000000
Number of Observations Used    1289.000000
Critical Value (1%)              -3.435433
Critical Value (5%)              -2.863785
Critical Value (10%)             -2.567965
dtype: float64
None
In [90]:
test_stationary_gdp_monthly = test_stationary_gdp_weekly.groupby('Par_Month').last()
In [91]:
print(color.BOLD +'GDP_US' + color.END)
print(adf_test(test_stationary_gdp_monthly['gdp_us']))


print(color.BOLD +'GDP_China' + color.END)
print(adf_test(test_stationary_gdp_monthly['gdp_china']))


print(color.BOLD +'GDP_Europe' + color.END)
print(adf_test(test_stationary_gdp_monthly['gdp_europe']))
GDP_US
Results of Augmented Dickey-Fuller Test:
Test Statistic                   0.994661
p-value                          0.994209
#Lags Used                       9.000000
Number of Observations Used    290.000000
Critical Value (1%)             -3.453102
Critical Value (5%)             -2.871559
Critical Value (10%)            -2.572108
dtype: float64
None
GDP_China
Results of Augmented Dickey-Fuller Test:
Test Statistic                   2.074122
p-value                          0.998762
#Lags Used                      15.000000
Number of Observations Used    284.000000
Critical Value (1%)             -3.453587
Critical Value (5%)             -2.871771
Critical Value (10%)            -2.572222
dtype: float64
None
GDP_Europe
Results of Augmented Dickey-Fuller Test:
Test Statistic                  -0.369412
p-value                          0.915082
#Lags Used                       9.000000
Number of Observations Used    290.000000
Critical Value (1%)             -3.453102
Critical Value (5%)             -2.871559
Critical Value (10%)            -2.572108
dtype: float64
None
In [92]:
first_dif_gdp_monthly = (np.log(test_stationary_gdp_monthly[['gdp_us','gdp_china','gdp_europe']].shift(0)) - np.log(test_stationary_gdp_monthly[['gdp_us','gdp_china','gdp_europe']].shift(1))).dropna()
first_dif_gdp_monthly_seasonal = first_dif_gdp_monthly.shift(0) - first_dif_gdp_monthly.shift(12)
first_dif_gdp_monthly_seasonal.dropna(inplace = True)
In [93]:
print(color.BOLD +'GDP_US' + color.END)
print(adf_test(first_dif_gdp_monthly['gdp_us']))


print(color.BOLD +'GDP_China' + color.END)
print(adf_test(first_dif_gdp_monthly['gdp_china']))


print(color.BOLD +'GDP_Europe' + color.END)
print(adf_test(first_dif_gdp_monthly['gdp_europe']))
GDP_US
Results of Augmented Dickey-Fuller Test:
Test Statistic                  -3.388407
p-value                          0.011360
#Lags Used                       8.000000
Number of Observations Used    290.000000
Critical Value (1%)             -3.453102
Critical Value (5%)             -2.871559
Critical Value (10%)            -2.572108
dtype: float64
None
GDP_China
Results of Augmented Dickey-Fuller Test:
Test Statistic                  -2.891636
p-value                          0.046329
#Lags Used                      14.000000
Number of Observations Used    284.000000
Critical Value (1%)             -3.453587
Critical Value (5%)             -2.871771
Critical Value (10%)            -2.572222
dtype: float64
None
GDP_Europe
Results of Augmented Dickey-Fuller Test:
Test Statistic                  -3.650664
p-value                          0.004863
#Lags Used                       8.000000
Number of Observations Used    290.000000
Critical Value (1%)             -3.453102
Critical Value (5%)             -2.871559
Critical Value (10%)            -2.572108
dtype: float64
None
In [94]:
print(color.BOLD +'GDP_US' + color.END)
print(adf_test(first_dif_gdp_monthly_seasonal['gdp_us']))


print(color.BOLD +'GDP_China' + color.END)
print(adf_test(first_dif_gdp_monthly_seasonal['gdp_china']))


print(color.BOLD +'GDP_Europe' + color.END)
print(adf_test(first_dif_gdp_monthly_seasonal['gdp_europe']))
GDP_US
Results of Augmented Dickey-Fuller Test:
Test Statistic                -6.182351e+00
p-value                        6.409760e-08
#Lags Used                     1.100000e+01
Number of Observations Used    2.750000e+02
Critical Value (1%)           -3.454355e+00
Critical Value (5%)           -2.872108e+00
Critical Value (10%)          -2.572401e+00
dtype: float64
None
GDP_China
Results of Augmented Dickey-Fuller Test:
Test Statistic                -6.365718e+00
p-value                        2.412759e-08
#Lags Used                     2.000000e+00
Number of Observations Used    2.840000e+02
Critical Value (1%)           -3.453587e+00
Critical Value (5%)           -2.871771e+00
Critical Value (10%)          -2.572222e+00
dtype: float64
None
GDP_Europe
Results of Augmented Dickey-Fuller Test:
Test Statistic                -7.061512e+00
p-value                        5.209056e-10
#Lags Used                     1.100000e+01
Number of Observations Used    2.750000e+02
Critical Value (1%)           -3.454355e+00
Critical Value (5%)           -2.872108e+00
Critical Value (10%)          -2.572401e+00
dtype: float64
None

2.3 Global temperature -- Stationary after first diff ** Becareful of inf data

In [95]:
print(adf_test(glob_temp['Celsius']))
print(' ')
print(kpss_test(glob_temp['Celsius']))
Results of Augmented Dickey-Fuller Test:
Test Statistic                  -1.452425
p-value                          0.556901
#Lags Used                       9.000000
Number of Observations Used    746.000000
Critical Value (1%)             -3.439146
Critical Value (5%)             -2.865422
Critical Value (10%)            -2.568837
dtype: float64
None
 
Results of KPSS Test:
Test Statistic            3.363103
p-value                   0.010000
Lags Used                20.000000
Critical Value (10%)      0.347000
Critical Value (5%)       0.463000
Critical Value (2.5%)     0.574000
Critical Value (1%)       0.739000
dtype: float64
None
C:\Users\DELL\Anaconda3\lib\site-packages\statsmodels\tsa\stattools.py:1276: InterpolationWarning: p-value is smaller than the indicated p-value
  warn("p-value is smaller than the indicated p-value", InterpolationWarning)
In [96]:
#Fix zero data
index_fix_data = glob_temp[glob_temp['Celsius'] == 0].index
for i in index_fix_data:
    glob_temp.loc[i] = glob_temp.loc[i-1].copy()
In [97]:
first_dif_temp = (np.log(glob_temp['Celsius'].shift(0)) - np.log(glob_temp['Celsius'].shift(1))).dropna()
first_dif_temp = first_dif_temp.to_frame()
C:\Users\DELL\Anaconda3\lib\site-packages\pandas\core\series.py:726: RuntimeWarning: invalid value encountered in log
  result = getattr(ufunc, method)(*inputs, **kwargs)
In [98]:
print(adf_test(first_dif_temp['Celsius']))
print(' ')
print(kpss_test(first_dif_temp['Celsius']))
Results of Augmented Dickey-Fuller Test:
Test Statistic                -9.902735e+00
p-value                        3.324598e-17
#Lags Used                     1.700000e+01
Number of Observations Used    6.200000e+02
Critical Value (1%)           -3.440941e+00
Critical Value (5%)           -2.866213e+00
Critical Value (10%)          -2.569259e+00
dtype: float64
None
 
Results of KPSS Test:
Test Statistic            0.024498
p-value                   0.100000
Lags Used                20.000000
Critical Value (10%)      0.347000
Critical Value (5%)       0.463000
Critical Value (2.5%)     0.574000
Critical Value (1%)       0.739000
dtype: float64
None
C:\Users\DELL\Anaconda3\lib\site-packages\statsmodels\tsa\stattools.py:1278: InterpolationWarning: p-value is greater than the indicated p-value
  warn("p-value is greater than the indicated p-value", InterpolationWarning)
In [99]:
#first_dif_temp.index
month_list = []
year_list = []
for i in glob_temp['Celsius'].index:
    month_list.append(str(i)[-2:])
    year_list.append(str(i)[:4])

glob_temp['Month'] = month_list
glob_temp['Year'] = year_list
In [100]:
#Global temp Month
#Change this line and title
index = 'Global temperature(Celsius)'


print(index +" Month")
print(adf_test(glob_temp['Celsius']))

glob_temp_month = np.log(glob_temp['Celsius'].shift(0)) - np.log(glob_temp['Celsius'].shift(1))
glob_temp_month = glob_temp_month.dropna()
print("First Diff " + index + " Month")
print(adf_test(glob_temp_month))

glob_temp_month = glob_temp_month - glob_temp_month.shift(12)
glob_temp_month = glob_temp_month.dropna()
print("First Diff seasonal"+index+" Month")
print(adf_test(glob_temp_month))

#Global temp Month

function = glob_temp.query('Month in ["12","03","06","09"]')['Celsius']
#function = function.groupby('Par_Month')[index].last()
function.dropna(inplace = True)

print(index + " Quarter")
print(adf_test(function))

function_2 = np.log(function.shift(0)) - np.log(function.shift(1))
function_2 = function_2.dropna()
print("First Diff "+index+" Quarter")
print(adf_test(function_2))

function_3 = function_2 - function_2.shift(4)
function_3 = function_3.dropna()
print("First Diff Seasonal "+index +" Quarter")
print(adf_test(function_3))
Global temperature(Celsius) Month
Results of Augmented Dickey-Fuller Test:
Test Statistic                  -1.447402
p-value                          0.559352
#Lags Used                       9.000000
Number of Observations Used    746.000000
Critical Value (1%)             -3.439146
Critical Value (5%)             -2.865422
Critical Value (10%)            -2.568837
dtype: float64
C:\Users\DELL\Anaconda3\lib\site-packages\pandas\core\series.py:726: RuntimeWarning: invalid value encountered in log
  result = getattr(ufunc, method)(*inputs, **kwargs)
None
First Diff Global temperature(Celsius) Month
Results of Augmented Dickey-Fuller Test:
Test Statistic                -9.902735e+00
p-value                        3.324598e-17
#Lags Used                     1.700000e+01
Number of Observations Used    6.200000e+02
Critical Value (1%)           -3.440941e+00
Critical Value (5%)           -2.866213e+00
Critical Value (10%)          -2.569259e+00
dtype: float64
None
First Diff seasonalGlobal temperature(Celsius) Month
Results of Augmented Dickey-Fuller Test:
C:\Users\DELL\Anaconda3\lib\site-packages\ipykernel_launcher.py:23: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
Test Statistic                -1.140574e+01
p-value                        7.457383e-21
#Lags Used                     1.700000e+01
Number of Observations Used    6.080000e+02
Critical Value (1%)           -3.441151e+00
Critical Value (5%)           -2.866305e+00
Critical Value (10%)          -2.569308e+00
dtype: float64
None
Global temperature(Celsius) Quarter
Results of Augmented Dickey-Fuller Test:
Test Statistic                  -0.485741
p-value                          0.894769
#Lags Used                       7.000000
Number of Observations Used    244.000000
Critical Value (1%)             -3.457438
Critical Value (5%)             -2.873459
Critical Value (10%)            -2.573122
dtype: float64
None
First Diff Global temperature(Celsius) Quarter
Results of Augmented Dickey-Fuller Test:
Test Statistic                -6.140355e+00
p-value                        7.999020e-08
#Lags Used                     1.500000e+01
Number of Observations Used    1.920000e+02
Critical Value (1%)           -3.464875e+00
Critical Value (5%)           -2.876714e+00
Critical Value (10%)          -2.574859e+00
dtype: float64
None
First Diff Seasonal Global temperature(Celsius) Quarter
Results of Augmented Dickey-Fuller Test:
Test Statistic                -6.265141e+00
p-value                        4.131569e-08
#Lags Used                     1.500000e+01
Number of Observations Used    1.880000e+02
Critical Value (1%)           -3.465620e+00
Critical Value (5%)           -2.877040e+00
Critical Value (10%)          -2.575032e+00
dtype: float64
None
In [101]:
glob_temp.Month = glob_temp.Month.astype(int).to_list()
glob_temp.Year = glob_temp.Year.astype(int).to_list()
In [102]:
glob_temp_df = pd.merge(oil_price,glob_temp, how = 'left', on = ['Year','Month'])
glob_temp_df = glob_temp_df[['Celsius']].dropna()
In [103]:
#weekly test stationary
glob_temp_df_stationary = np.log(glob_temp_df) - np.log(glob_temp_df).shift(52)
glob_temp_df_stationary.dropna(inplace = True)
In [104]:
glob_temp_df_stationary
Out[104]:
Celsius
52 0.000000
53 -0.067441
54 -0.067441
55 -0.067441
56 0.177681
... ...
1557 -0.297252
1558 -0.297252
1559 -0.297252
1560 -0.297252
1561 -0.379490

1510 rows × 1 columns

In [105]:
print(adf_test(glob_temp_df['Celsius'])) 
print(adf_test(glob_temp_df_stationary['Celsius']))
Results of Augmented Dickey-Fuller Test:
Test Statistic                   -2.577654
p-value                           0.097704
#Lags Used                       13.000000
Number of Observations Used    1548.000000
Critical Value (1%)              -3.434581
Critical Value (5%)              -2.863409
Critical Value (10%)             -2.567765
dtype: float64
None
Results of Augmented Dickey-Fuller Test:
Test Statistic                -5.871372e+00
p-value                        3.234318e-07
#Lags Used                     1.300000e+01
Number of Observations Used    1.496000e+03
Critical Value (1%)           -3.434729e+00
Critical Value (5%)           -2.863474e+00
Critical Value (10%)          -2.567800e+00
dtype: float64
None

2.4 CO2 Emission -- Stationary after first diff

In [106]:
print(adf_test(world_co2_em['World_Emission_general']))
print(' ')
print(kpss_test(world_co2_em['World_Emission_general']))
Results of Augmented Dickey-Fuller Test:
Test Statistic                  0.530341
p-value                         0.985767
#Lags Used                      0.000000
Number of Observations Used    56.000000
Critical Value (1%)            -3.552928
Critical Value (5%)            -2.914731
Critical Value (10%)           -2.595137
dtype: float64
None
 
Results of KPSS Test:
Test Statistic            0.597758
p-value                   0.022840
Lags Used                11.000000
Critical Value (10%)      0.347000
Critical Value (5%)       0.463000
Critical Value (2.5%)     0.574000
Critical Value (1%)       0.739000
dtype: float64
None
In [107]:
first_dif_em = (np.log(world_co2_em['World_Emission_general'].shift(0)) - np.log(world_co2_em['World_Emission_general'].shift(1))).dropna()
first_dif_em = first_dif_em.to_frame()
In [108]:
print(adf_test(first_dif_em['World_Emission_general']))
print(' ')
print(kpss_test(first_dif_em['World_Emission_general']))
Results of Augmented Dickey-Fuller Test:
Test Statistic                 -5.057401
p-value                         0.000017
#Lags Used                      0.000000
Number of Observations Used    55.000000
Critical Value (1%)            -3.555273
Critical Value (5%)            -2.915731
Critical Value (10%)           -2.595670
dtype: float64
None
 
Results of KPSS Test:
Test Statistic            0.254757
p-value                   0.100000
Lags Used                11.000000
Critical Value (10%)      0.347000
Critical Value (5%)       0.463000
Critical Value (2.5%)     0.574000
Critical Value (1%)       0.739000
dtype: float64
None
C:\Users\DELL\Anaconda3\lib\site-packages\statsmodels\tsa\stattools.py:1278: InterpolationWarning: p-value is greater than the indicated p-value
  warn("p-value is greater than the indicated p-value", InterpolationWarning)

2.5 CO2 Concentration -- Stationary after first diff

In [109]:
print(adf_test(co2_conc['average']))
print(' ')
print(kpss_test(co2_conc['average']))
Results of Augmented Dickey-Fuller Test:
Test Statistic                    0.265888
p-value                           0.975724
#Lags Used                       27.000000
Number of Observations Used    2406.000000
Critical Value (1%)              -3.433071
Critical Value (5%)              -2.862742
Critical Value (10%)             -2.567410
dtype: float64
None
 
Results of KPSS Test:
Test Statistic            8.664788
p-value                   0.010000
Lags Used                27.000000
Critical Value (10%)      0.347000
Critical Value (5%)       0.463000
Critical Value (2.5%)     0.574000
Critical Value (1%)       0.739000
dtype: float64
None
C:\Users\DELL\Anaconda3\lib\site-packages\statsmodels\tsa\stattools.py:1276: InterpolationWarning: p-value is smaller than the indicated p-value
  warn("p-value is smaller than the indicated p-value", InterpolationWarning)
In [110]:
first_dif_conc = (np.log(co2_conc.average.shift(0)) - np.log(co2_conc.average.shift(1))).dropna()
In [111]:
print(adf_test(first_dif_conc))
print(' ')
print(kpss_test(first_dif_conc))
Results of Augmented Dickey-Fuller Test:
Test Statistic                -1.549584e+01
p-value                        2.451206e-28
#Lags Used                     2.700000e+01
Number of Observations Used    2.405000e+03
Critical Value (1%)           -3.433072e+00
Critical Value (5%)           -2.862743e+00
Critical Value (10%)          -2.567410e+00
dtype: float64
None
 
Results of KPSS Test:
Test Statistic            0.022695
p-value                   0.100000
Lags Used                27.000000
Critical Value (10%)      0.347000
Critical Value (5%)       0.463000
Critical Value (2.5%)     0.574000
Critical Value (1%)       0.739000
dtype: float64
None
C:\Users\DELL\Anaconda3\lib\site-packages\statsmodels\tsa\stattools.py:1278: InterpolationWarning: p-value is greater than the indicated p-value
  warn("p-value is greater than the indicated p-value", InterpolationWarning)

3.) Quarterly analysis

3.1 Forming an analysis table including CO2 Concentration, Oil Price, GDPs, and Global temperature

In [112]:
# Choosing last Month data
quarter_oil_co2_df = oil_co2_df.groupby('Par_Month').last().copy()
In [113]:
glob_temp
Out[113]:
Celsius Month Year
Par_Month
195801 0.32 1 1958
195802 0.22 2 1958
195803 0.15 3 1958
195804 0.10 4 1958
195805 0.09 5 1958
... ... ... ...
202008 0.94 8 2020
202009 0.95 9 2020
202010 0.84 10 2020
202011 0.96 11 2020
202012 0.78 12 2020

756 rows × 3 columns

In [114]:
gdp_df.drop(columns = ['Year','Month','Quarter'])
Out[114]:
gdp_date gdp_us gdp_china gdp_europe
Par_Month
199501 1995-01-01 7522.289 1.211170e+12 1811683.8
199504 1995-04-01 7580.997 1.461290e+12 1823657.0
199507 1995-07-01 7683.125 1.616410e+12 1855373.1
199510 1995-10-01 7772.586 1.845120e+12 1873811.6
199601 1996-01-01 7868.468 1.462800e+12 1895898.1
... ... ... ... ...
201810 2018-10-01 20909.853 2.588089e+13 4035641.0
201901 2019-01-01 21115.309 2.180628e+13 4087037.5
201904 2019-04-01 21329.877 2.425738e+13 4110867.9
201907 2019-07-01 21540.325 2.522087e+13 4120638.6
201910 2019-10-01 21747.394 2.780197e+13 4179068.3

100 rows × 4 columns

In [115]:
#Joining data to create big dataframe

q_analysis_df = quarter_oil_co2_df.join(gdp_df.drop(columns = ['Year','Month','Quarter'])).dropna(subset=['gdp_date','gdp_us','gdp_china','gdp_europe'])
q_analysis_df = q_analysis_df.join(glob_temp['Celsius'])
In [116]:
#Rename Carbon Dioxide concentration 

temp = q_analysis_df['average']
q_analysis_df = q_analysis_df.drop(columns = 'average')
q_analysis_df['CO2_Concentration'] = temp

q_analysis_df = q_analysis_df.drop(columns = 'gdp_date')
q_analysis_df.head()
Out[116]:
Weekindex Date Year Month Week Day Par_Day oil_spot_WTI oil_spot_Brent future_oil_contract_1 ... decimal ndays 1_year_ago 10_years_ago increase_since_1800 gdp_us gdp_china gdp_europe Celsius CO2_Concentration
Par_Month
199501 474 1/27/1995 1995 1 4 27 19950427 17.95 16.38 17.95 ... 1995.0781 7.0 358.35 345.73 79.68 7522.289 1.211170e+12 1811683.8 0.56 360.14
199504 487 4/28/1995 1995 4 17 28 19950528 20.36 18.98 20.38 ... 1995.3274 5.0 362.17 349.10 79.75 7580.997 1.461290e+12 1823657.0 0.45 362.83
199507 500 7/28/1995 1995 7 30 28 19950528 17.43 15.93 17.43 ... 1995.5767 6.0 358.58 345.72 80.71 7683.125 1.616410e+12 1855373.1 0.42 360.14
199510 513 10/27/1995 1995 10 43 27 19950527 17.54 16.35 17.54 ... 1995.8260 6.0 356.61 343.79 81.70 7772.586 1.845120e+12 1873811.6 0.44 358.83
199601 526 1/26/1996 1996 1 4 26 19960626 17.68 16.70 17.73 ... 1996.0751 6.0 360.12 346.49 81.81 7868.468 1.462800e+12 1895898.1 0.25 362.34

5 rows × 37 columns

In [117]:
#Create first difference

temp_frame = (np.log(q_analysis_df[['gdp_china','gdp_us','gdp_europe','Celsius','CO2_Concentration']].shift(0)) - np.log(q_analysis_df[['gdp_china','gdp_us','gdp_europe','Celsius','CO2_Concentration']].shift(1)))
temp_frame = temp_frame.rename(columns = {'gdp_china' : 'chg_gdp_china','gdp_europe':'chg_gdp_europe','gdp_us':'chg_gdp_us','Celsius':'chg_celsius','CO2_Concentration':'chg_co2_concentration'})
q_analysis_df =  q_analysis_df.merge(temp_frame, how='inner', on='Par_Month')
                                     
q_analysis_df.head()
q_analysis_df = q_analysis_df.iloc[1:]
In [118]:
q_analysis_df.columns
Out[118]:
Index(['Weekindex', 'Date', 'Year', 'Month', 'Week', 'Day', 'Par_Day',
       'oil_spot_WTI', 'oil_spot_Brent', 'future_oil_contract_1',
       'sugar_price_us', 'ethanol_price_us', 'chg_oil_spot_WTI',
       'chg_oil_spot_Brent', 'chg_oil_spot_WTI_Positive',
       'chg_oil_spot_WTI_Negative', 'chg_oil_future_contract1',
       'chg_oil_future_contract1_Positive',
       'chg_oil_future_contract1_Negative', 'Gasoline_Price_US',
       'chg_Gasoline_price_US', 'chg_Gasoline_price_US_Positive',
       'chg_Gasoline_price_US_future', 'Date_edited', 'year', 'month', 'day',
       'decimal', 'ndays', '1_year_ago', '10_years_ago', 'increase_since_1800',
       'gdp_us', 'gdp_china', 'gdp_europe', 'Celsius', 'CO2_Concentration',
       'chg_gdp_china', 'chg_gdp_us', 'chg_gdp_europe', 'chg_celsius',
       'chg_co2_concentration'],
      dtype='object')
In [119]:
#Export data to output table
q_analysis_df.to_csv('quarterly_analysis_prep_data.csv')
In [120]:
q_analysis_df_correl = q_analysis_df[[ 'Gasoline_Price_US','CO2_Concentration','oil_spot_WTI', 'oil_spot_Brent', 'future_oil_contract_1','sugar_price_us', 'ethanol_price_us','gdp_us', 'gdp_china', 'gdp_europe', 'Celsius']]
q_analysis_df_correl.dropna(inplace = True)
C:\Users\DELL\Anaconda3\lib\site-packages\ipykernel_launcher.py:2: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  
In [121]:
q_analysis_df_correl_diff = np.log(q_analysis_df_correl) - np.log(q_analysis_df_correl.shift(1))
q_analysis_df_correl_diff.dropna(inplace = True)
In [122]:
from statsmodels.tsa.stattools import grangercausalitytests

maxlag=10
test = 'ssr-chi2test'
def grangers_causality_matrix(X_train, variables, test = 'ssr_chi2test', verbose=False):
    dataset = pd.DataFrame(np.zeros((len(variables), len(variables))), columns=variables, index=variables)
    for c in dataset.columns:
        for r in dataset.index:
            test_result = grangercausalitytests(X_train[[r,c]], maxlag=maxlag, verbose=False)
            p_values = [round(test_result[i+1][0][test][1],4) for i in range(maxlag)]
            if verbose: print(f'Y = {r}, X = {c}, P Values = {p_values}')
            min_p_value = np.min(p_values)
            dataset.loc[r,c] = min_p_value
    dataset.columns = [var + '_x' for var in variables]
    dataset.index = [var + '_y' for var in variables]
    return dataset

granger_test = grangers_causality_matrix(q_analysis_df_correl_diff , variables = q_analysis_df_correl_diff.columns)
In [123]:
granger_test
Out[123]:
Gasoline_Price_US_x CO2_Concentration_x oil_spot_WTI_x oil_spot_Brent_x future_oil_contract_1_x sugar_price_us_x ethanol_price_us_x gdp_us_x gdp_china_x gdp_europe_x Celsius_x
Gasoline_Price_US_y 1.0000 0.0000 0.0000 0.0000 0.0000 0.0061 0.0043 0.0175 0.0000 0.2026 0.0005
CO2_Concentration_y 0.0000 1.0000 0.0007 0.0000 0.0007 0.0043 0.0072 0.2380 0.0000 0.0020 0.0002
oil_spot_WTI_y 0.0027 0.0164 1.0000 0.1696 0.0740 0.0429 0.0019 0.1867 0.0000 0.1376 0.0001
oil_spot_Brent_y 0.0000 0.0215 0.4103 1.0000 0.5969 0.0160 0.0003 0.1892 0.0002 0.2487 0.0001
future_oil_contract_1_y 0.0010 0.0214 0.0787 0.1615 1.0000 0.0381 0.0026 0.1697 0.0001 0.1409 0.0001
sugar_price_us_y 0.0002 0.0090 0.0004 0.0008 0.0002 1.0000 0.0216 0.0000 0.0086 0.0000 0.0210
ethanol_price_us_y 0.0510 0.0050 0.0555 0.0422 0.0335 0.0031 1.0000 0.0530 0.0001 0.0266 0.0572
gdp_us_y 0.0033 0.0539 0.0572 0.0718 0.0711 0.6176 0.0209 1.0000 0.0000 0.0088 0.0000
gdp_china_y 0.0001 0.0000 0.0003 0.0001 0.0002 0.0139 0.0003 0.0000 1.0000 0.0036 0.0000
gdp_europe_y 0.3444 0.4020 0.3223 0.1662 0.2953 0.3823 0.3034 0.0000 0.0238 1.0000 0.0000
Celsius_y 0.0062 0.1259 0.0235 0.0315 0.0228 0.0002 0.0434 0.0755 0.0000 0.0045 1.0000
In [124]:
import seaborn as sns
corr =round(q_analysis_df_correl_diff.corr(),2)

mask = np.zeros_like(corr, dtype=np.bool)
mask[np.triu_indices_from(mask)] = True

sns.heatmap(corr, xticklabels = corr.columns.values,yticklabels = corr.columns.values, annot = True,annot_kws = {'size':12}, cmap = 'vlag_r', mask = mask)
heat_map = plt.gcf()
heat_map.set_size_inches(15,8)
plt.xticks(fontsize = 15)
plt.yticks(fontsize = 15)
plt.show()
#Weekly Monthly timeframe

3.2 Regression analysis -- Oil to CO2 concentration -- Best model is using lag of each variables up to 8 lags

In [125]:
quick_anaysis = q_analysis_df.copy()
In [126]:
# test perfect number of lags used in model
import statsmodels.api as sm

nlag = 20

for i in range(nlag+1):
    #print(i)
    quick_anaysis_df_loop = quick_anaysis.copy()
    #running = i.copy()
    column_names = ['chg_oil_spot_WTI_Positive','chg_oil_spot_WTI_Negative','chg_gdp_us','chg_gdp_china','chg_gdp_europe']
    print("Number of lag : ", str(i))
    while i > 0:
        text = 'lag' + '_' + str(i)
        
        quick_anaysis_df_loop[text] = quick_anaysis['oil_spot_WTI'].shift(i)
        
        quick_anaysis_df_loop['chg_oil_spot_WTI' + "_" + text] = quick_anaysis['oil_spot_WTI'].shift(i)
        
        quick_anaysis_df_loop['chg_gdp_us' + "_" + text] = quick_anaysis['gdp_us'].shift(i)
        
        quick_anaysis_df_loop['chg_gdp_china' + "_" + text] = quick_anaysis['gdp_china'].shift(i)
        
        quick_anaysis_df_loop['chg_gdp_europe' + "_" + text] = quick_anaysis['gdp_europe'].shift(i)

        column_names.append('chg_oil_spot_WTI' + "_" + text)
        column_names.append('chg_gdp_us' + "_" + text)
        column_names.append('chg_gdp_china' + "_" + text)
        column_names.append('chg_gdp_europe' + "_" + text)

        i = i - 1
        #print(i+1)
    #print(" ")
    quick_anaysis_df_loop = quick_anaysis_df_loop.dropna()
    
    x = quick_anaysis_df_loop[column_names] 
    reg_model = sm.OLS(quick_anaysis_df_loop['chg_co2_concentration'],x)
    result = reg_model.fit()
    print("R-squared : ", result.rsquared)
    print("P-value : ")
    print(round(result.pvalues,4))
    print(" ")
Number of lag :  0
R-squared :  0.2649221825535426
P-value : 
chg_oil_spot_WTI_Positive    0.3944
chg_oil_spot_WTI_Negative    0.4774
chg_gdp_us                   0.7664
chg_gdp_china                0.0001
chg_gdp_europe               0.4518
dtype: float64
 
Number of lag :  1
R-squared :  0.3593579802615039
P-value : 
chg_oil_spot_WTI_Positive    0.8427
chg_oil_spot_WTI_Negative    0.6968
chg_gdp_us                   0.9188
chg_gdp_china                0.0000
chg_gdp_europe               0.7811
chg_oil_spot_WTI_lag_1       0.5202
chg_gdp_us_lag_1             0.0388
chg_gdp_china_lag_1          0.0156
chg_gdp_europe_lag_1         0.0581
dtype: float64
 
Number of lag :  2
R-squared :  0.77368318146539
P-value : 
chg_oil_spot_WTI_Positive    0.8747
chg_oil_spot_WTI_Negative    0.8758
chg_gdp_us                   0.0932
chg_gdp_china                0.0000
chg_gdp_europe               0.6889
chg_oil_spot_WTI_lag_2       0.3638
chg_gdp_us_lag_2             0.0651
chg_gdp_china_lag_2          0.0000
chg_gdp_europe_lag_2         0.1185
chg_oil_spot_WTI_lag_1       0.1943
chg_gdp_us_lag_1             0.1571
chg_gdp_china_lag_1          0.0000
chg_gdp_europe_lag_1         0.6574
dtype: float64
 
Number of lag :  3
R-squared :  0.8162466033642268
P-value : 
chg_oil_spot_WTI_Positive    0.5698
chg_oil_spot_WTI_Negative    0.7852
chg_gdp_us                   0.0098
chg_gdp_china                0.0000
chg_gdp_europe               0.9085
chg_oil_spot_WTI_lag_3       0.4508
chg_gdp_us_lag_3             0.3091
chg_gdp_china_lag_3          0.0086
chg_gdp_europe_lag_3         0.2946
chg_oil_spot_WTI_lag_2       0.7811
chg_gdp_us_lag_2             0.6884
chg_gdp_china_lag_2          0.0000
chg_gdp_europe_lag_2         0.8289
chg_oil_spot_WTI_lag_1       0.4396
chg_gdp_us_lag_1             0.1903
chg_gdp_china_lag_1          0.0000
chg_gdp_europe_lag_1         0.5738
dtype: float64
 
Number of lag :  4
R-squared :  0.8490880742790302
P-value : 
chg_oil_spot_WTI_Positive    0.0010
chg_oil_spot_WTI_Negative    0.0010
chg_gdp_us                   0.0010
chg_gdp_china                0.0010
chg_gdp_europe               0.0010
chg_oil_spot_WTI_lag_4       0.1673
chg_gdp_us_lag_4             0.0713
chg_gdp_china_lag_4          0.0386
chg_gdp_europe_lag_4         0.0928
chg_oil_spot_WTI_lag_3       0.1760
chg_gdp_us_lag_3             0.1930
chg_gdp_china_lag_3          0.0055
chg_gdp_europe_lag_3         0.2337
chg_oil_spot_WTI_lag_2       0.8673
chg_gdp_us_lag_2             0.7392
chg_gdp_china_lag_2          0.0000
chg_gdp_europe_lag_2         0.6895
chg_oil_spot_WTI_lag_1       0.5266
chg_gdp_us_lag_1             0.2398
chg_gdp_china_lag_1          0.0182
chg_gdp_europe_lag_1         0.2611
dtype: float64
 
Number of lag :  5
R-squared :  0.8559646958943945
P-value : 
chg_oil_spot_WTI_Positive    0.0089
chg_oil_spot_WTI_Negative    0.0090
chg_gdp_us                   0.0089
chg_gdp_china                0.0089
chg_gdp_europe               0.0089
chg_oil_spot_WTI_lag_5       0.2609
chg_gdp_us_lag_5             0.7050
chg_gdp_china_lag_5          0.7904
chg_gdp_europe_lag_5         0.9980
chg_oil_spot_WTI_lag_4       0.0672
chg_gdp_us_lag_4             0.1964
chg_gdp_china_lag_4          0.0276
chg_gdp_europe_lag_4         0.2452
chg_oil_spot_WTI_lag_3       0.1324
chg_gdp_us_lag_3             0.2159
chg_gdp_china_lag_3          0.0148
chg_gdp_europe_lag_3         0.2052
chg_oil_spot_WTI_lag_2       0.9938
chg_gdp_us_lag_2             0.5794
chg_gdp_china_lag_2          0.0000
chg_gdp_europe_lag_2         0.7357
chg_oil_spot_WTI_lag_1       0.4434
chg_gdp_us_lag_1             0.1551
chg_gdp_china_lag_1          0.2781
chg_gdp_europe_lag_1         0.2599
dtype: float64
 
Number of lag :  6
R-squared :  0.8614373573169404
P-value : 
chg_oil_spot_WTI_Positive    0.7073
chg_oil_spot_WTI_Negative    0.0199
chg_gdp_us                   0.0199
chg_gdp_china                0.0199
chg_gdp_europe               0.0199
chg_oil_spot_WTI_lag_6       0.1700
chg_gdp_us_lag_6             0.9031
chg_gdp_china_lag_6          0.4362
chg_gdp_europe_lag_6         0.4250
chg_oil_spot_WTI_lag_5       0.8396
chg_gdp_us_lag_5             0.6529
chg_gdp_china_lag_5          0.4932
chg_gdp_europe_lag_5         0.3978
chg_oil_spot_WTI_lag_4       0.0809
chg_gdp_us_lag_4             0.1238
chg_gdp_china_lag_4          0.0461
chg_gdp_europe_lag_4         0.7391
chg_oil_spot_WTI_lag_3       0.2956
chg_gdp_us_lag_3             0.2356
chg_gdp_china_lag_3          0.1048
chg_gdp_europe_lag_3         0.4371
chg_oil_spot_WTI_lag_2       0.9938
chg_gdp_us_lag_2             0.5547
chg_gdp_china_lag_2          0.0877
chg_gdp_europe_lag_2         0.7074
chg_oil_spot_WTI_lag_1       0.3795
chg_gdp_us_lag_1             0.2440
chg_gdp_china_lag_1          0.3075
chg_gdp_europe_lag_1         0.4885
dtype: float64
 
Number of lag :  7
R-squared :  0.8670197353334741
P-value : 
chg_oil_spot_WTI_Positive    0.6923
chg_oil_spot_WTI_Negative    0.0332
chg_gdp_us                   0.0332
chg_gdp_china                0.0332
chg_gdp_europe               0.0331
chg_oil_spot_WTI_lag_7       0.9439
chg_gdp_us_lag_7             0.6452
chg_gdp_china_lag_7          0.4589
chg_gdp_europe_lag_7         0.5089
chg_oil_spot_WTI_lag_6       0.2049
chg_gdp_us_lag_6             0.4699
chg_gdp_china_lag_6          0.9902
chg_gdp_europe_lag_6         0.9352
chg_oil_spot_WTI_lag_5       0.8470
chg_gdp_us_lag_5             0.8291
chg_gdp_china_lag_5          0.5806
chg_gdp_europe_lag_5         0.7094
chg_oil_spot_WTI_lag_4       0.0500
chg_gdp_us_lag_4             0.1142
chg_gdp_china_lag_4          0.0742
chg_gdp_europe_lag_4         0.6048
chg_oil_spot_WTI_lag_3       0.2915
chg_gdp_us_lag_3             0.2193
chg_gdp_china_lag_3          0.5521
chg_gdp_europe_lag_3         0.3741
chg_oil_spot_WTI_lag_2       0.9302
chg_gdp_us_lag_2             0.6397
chg_gdp_china_lag_2          0.5538
chg_gdp_europe_lag_2         0.7188
chg_oil_spot_WTI_lag_1       0.3269
chg_gdp_us_lag_1             0.2381
chg_gdp_china_lag_1          0.4128
chg_gdp_europe_lag_1         0.4996
dtype: float64
 
Number of lag :  8
R-squared :  0.8914691411441756
P-value : 
chg_oil_spot_WTI_Positive    0.1436
chg_oil_spot_WTI_Negative    0.1436
chg_gdp_us                   0.1436
chg_gdp_china                0.1435
chg_gdp_europe               0.1436
chg_oil_spot_WTI_lag_8       0.4233
chg_gdp_us_lag_8             0.4710
chg_gdp_china_lag_8          0.0747
chg_gdp_europe_lag_8         0.0489
chg_oil_spot_WTI_lag_7       0.8534
chg_gdp_us_lag_7             0.6220
chg_gdp_china_lag_7          0.0517
chg_gdp_europe_lag_7         0.0515
chg_oil_spot_WTI_lag_6       0.1722
chg_gdp_us_lag_6             0.2309
chg_gdp_china_lag_6          0.8461
chg_gdp_europe_lag_6         0.5346
chg_oil_spot_WTI_lag_5       0.2574
chg_gdp_us_lag_5             0.3799
chg_gdp_china_lag_5          0.3128
chg_gdp_europe_lag_5         0.6631
chg_oil_spot_WTI_lag_4       0.0111
chg_gdp_us_lag_4             0.0123
chg_gdp_china_lag_4          0.0125
chg_gdp_europe_lag_4         0.7843
chg_oil_spot_WTI_lag_3       0.2873
chg_gdp_us_lag_3             0.0794
chg_gdp_china_lag_3          0.0666
chg_gdp_europe_lag_3         0.7234
chg_oil_spot_WTI_lag_2       0.3512
chg_gdp_us_lag_2             0.3338
chg_gdp_china_lag_2          0.7185
chg_gdp_europe_lag_2         0.2553
chg_oil_spot_WTI_lag_1       0.1738
chg_gdp_us_lag_1             0.0183
chg_gdp_china_lag_1          0.2655
chg_gdp_europe_lag_1         0.0790
dtype: float64
 
Number of lag :  9
R-squared :  0.8976619236603729
P-value : 
chg_oil_spot_WTI_Positive    0.4685
chg_oil_spot_WTI_Negative    0.0641
chg_gdp_us                   0.7020
chg_gdp_china                0.0044
chg_gdp_europe               0.0289
chg_oil_spot_WTI_lag_9       0.9392
chg_gdp_us_lag_9             0.2835
chg_gdp_china_lag_9          0.3615
chg_gdp_europe_lag_9         0.3941
chg_oil_spot_WTI_lag_8       0.7452
chg_gdp_us_lag_8             0.7759
chg_gdp_china_lag_8          0.1385
chg_gdp_europe_lag_8         0.1853
chg_oil_spot_WTI_lag_7       0.9321
chg_gdp_us_lag_7             0.3708
chg_gdp_china_lag_7          0.0900
chg_gdp_europe_lag_7         0.0378
chg_oil_spot_WTI_lag_6       0.1939
chg_gdp_us_lag_6             0.1267
chg_gdp_china_lag_6          0.9367
chg_gdp_europe_lag_6         0.2961
chg_oil_spot_WTI_lag_5       0.2759
chg_gdp_us_lag_5             0.6309
chg_gdp_china_lag_5          0.1792
chg_gdp_europe_lag_5         0.9670
chg_oil_spot_WTI_lag_4       0.0069
chg_gdp_us_lag_4             0.0214
chg_gdp_china_lag_4          0.0469
chg_gdp_europe_lag_4         0.6609
chg_oil_spot_WTI_lag_3       0.3780
chg_gdp_us_lag_3             0.1200
chg_gdp_china_lag_3          0.1177
chg_gdp_europe_lag_3         0.5907
chg_oil_spot_WTI_lag_2       0.2203
chg_gdp_us_lag_2             0.2329
chg_gdp_china_lag_2          0.7015
chg_gdp_europe_lag_2         0.2844
chg_oil_spot_WTI_lag_1       0.0850
chg_gdp_us_lag_1             0.0069
chg_gdp_china_lag_1          0.2808
chg_gdp_europe_lag_1         0.0448
dtype: float64
 
Number of lag :  10
R-squared :  0.9212248782908983
P-value : 
chg_oil_spot_WTI_Positive    0.4951
chg_oil_spot_WTI_Negative    0.1962
chg_gdp_us                   0.8095
chg_gdp_china                0.0288
chg_gdp_europe               0.1836
chg_oil_spot_WTI_lag_10      0.4657
chg_gdp_us_lag_10            0.1161
chg_gdp_china_lag_10         0.1055
chg_gdp_europe_lag_10        0.1745
chg_oil_spot_WTI_lag_9       0.4500
chg_gdp_us_lag_9             0.1244
chg_gdp_china_lag_9          0.3910
chg_gdp_europe_lag_9         0.3812
chg_oil_spot_WTI_lag_8       0.6413
chg_gdp_us_lag_8             0.7843
chg_gdp_china_lag_8          0.2937
chg_gdp_europe_lag_8         0.0786
chg_oil_spot_WTI_lag_7       0.3826
chg_gdp_us_lag_7             0.0825
chg_gdp_china_lag_7          0.1386
chg_gdp_europe_lag_7         0.0208
chg_oil_spot_WTI_lag_6       0.0634
chg_gdp_us_lag_6             0.0232
chg_gdp_china_lag_6          0.3022
chg_gdp_europe_lag_6         0.1053
chg_oil_spot_WTI_lag_5       0.3758
chg_gdp_us_lag_5             0.9992
chg_gdp_china_lag_5          0.9690
chg_gdp_europe_lag_5         0.6952
chg_oil_spot_WTI_lag_4       0.0260
chg_gdp_us_lag_4             0.0208
chg_gdp_china_lag_4          0.1194
chg_gdp_europe_lag_4         0.4716
chg_oil_spot_WTI_lag_3       0.7641
chg_gdp_us_lag_3             0.0967
chg_gdp_china_lag_3          0.1503
chg_gdp_europe_lag_3         0.4597
chg_oil_spot_WTI_lag_2       0.1440
chg_gdp_us_lag_2             0.1057
chg_gdp_china_lag_2          0.6194
chg_gdp_europe_lag_2         0.1685
chg_oil_spot_WTI_lag_1       0.2163
chg_gdp_us_lag_1             0.0112
chg_gdp_china_lag_1          0.3046
chg_gdp_europe_lag_1         0.1208
dtype: float64
 
Number of lag :  11
R-squared :  0.9396713854399453
P-value : 
chg_oil_spot_WTI_Positive    0.7626
chg_oil_spot_WTI_Negative    0.1249
chg_gdp_us                   0.4575
chg_gdp_china                0.0443
chg_gdp_europe               0.8400
chg_oil_spot_WTI_lag_11      0.1343
chg_gdp_us_lag_11            0.1050
chg_gdp_china_lag_11         0.2193
chg_gdp_europe_lag_11        0.1572
chg_oil_spot_WTI_lag_10      0.3918
chg_gdp_us_lag_10            0.9190
chg_gdp_china_lag_10         0.6304
chg_gdp_europe_lag_10        0.7701
chg_oil_spot_WTI_lag_9       0.4506
chg_gdp_us_lag_9             0.3031
chg_gdp_china_lag_9          0.3562
chg_gdp_europe_lag_9         0.5253
chg_oil_spot_WTI_lag_8       0.3266
chg_gdp_us_lag_8             0.5833
chg_gdp_china_lag_8          0.2181
chg_gdp_europe_lag_8         0.2076
chg_oil_spot_WTI_lag_7       0.4619
chg_gdp_us_lag_7             0.1760
chg_gdp_china_lag_7          0.8467
chg_gdp_europe_lag_7         0.3547
chg_oil_spot_WTI_lag_6       0.0622
chg_gdp_us_lag_6             0.0418
chg_gdp_china_lag_6          0.6923
chg_gdp_europe_lag_6         0.2929
chg_oil_spot_WTI_lag_5       0.2649
chg_gdp_us_lag_5             0.8923
chg_gdp_china_lag_5          0.4114
chg_gdp_europe_lag_5         0.9457
chg_oil_spot_WTI_lag_4       0.0127
chg_gdp_us_lag_4             0.0426
chg_gdp_china_lag_4          0.1071
chg_gdp_europe_lag_4         0.6473
chg_oil_spot_WTI_lag_3       0.3738
chg_gdp_us_lag_3             0.0740
chg_gdp_china_lag_3          0.2036
chg_gdp_europe_lag_3         0.2129
chg_oil_spot_WTI_lag_2       0.0929
chg_gdp_us_lag_2             0.0296
chg_gdp_china_lag_2          0.1928
chg_gdp_europe_lag_2         0.5929
chg_oil_spot_WTI_lag_1       0.2399
chg_gdp_us_lag_1             0.0102
chg_gdp_china_lag_1          0.0697
chg_gdp_europe_lag_1         0.8636
dtype: float64
 
Number of lag :  12
R-squared :  0.9488339123684045
P-value : 
chg_oil_spot_WTI_Positive    0.5291
chg_oil_spot_WTI_Negative    0.1084
chg_gdp_us                   0.9381
chg_gdp_china                0.2800
chg_gdp_europe               0.3471
chg_oil_spot_WTI_lag_12      0.9017
chg_gdp_us_lag_12            0.6730
chg_gdp_china_lag_12         0.7516
chg_gdp_europe_lag_12        0.2404
chg_oil_spot_WTI_lag_11      0.5452
chg_gdp_us_lag_11            0.5349
chg_gdp_china_lag_11         0.9535
chg_gdp_europe_lag_11        0.0874
chg_oil_spot_WTI_lag_10      0.8563
chg_gdp_us_lag_10            0.8609
chg_gdp_china_lag_10         0.4789
chg_gdp_europe_lag_10        0.9216
chg_oil_spot_WTI_lag_9       0.9277
chg_gdp_us_lag_9             0.4117
chg_gdp_china_lag_9          0.4961
chg_gdp_europe_lag_9         0.4281
chg_oil_spot_WTI_lag_8       0.8400
chg_gdp_us_lag_8             0.9971
chg_gdp_china_lag_8          0.7182
chg_gdp_europe_lag_8         0.4584
chg_oil_spot_WTI_lag_7       0.3991
chg_gdp_us_lag_7             0.2477
chg_gdp_china_lag_7          0.6420
chg_gdp_europe_lag_7         0.2217
chg_oil_spot_WTI_lag_6       0.0716
chg_gdp_us_lag_6             0.0396
chg_gdp_china_lag_6          0.9840
chg_gdp_europe_lag_6         0.3677
chg_oil_spot_WTI_lag_5       0.3499
chg_gdp_us_lag_5             0.8032
chg_gdp_china_lag_5          0.9989
chg_gdp_europe_lag_5         0.9783
chg_oil_spot_WTI_lag_4       0.0294
chg_gdp_us_lag_4             0.0394
chg_gdp_china_lag_4          0.5625
chg_gdp_europe_lag_4         0.3994
chg_oil_spot_WTI_lag_3       0.8357
chg_gdp_us_lag_3             0.1472
chg_gdp_china_lag_3          0.6066
chg_gdp_europe_lag_3         0.3471
chg_oil_spot_WTI_lag_2       0.1160
chg_gdp_us_lag_2             0.2094
chg_gdp_china_lag_2          0.3885
chg_gdp_europe_lag_2         0.5593
chg_oil_spot_WTI_lag_1       0.1545
chg_gdp_us_lag_1             0.0171
chg_gdp_china_lag_1          0.5058
chg_gdp_europe_lag_1         0.3264
dtype: float64
 
Number of lag :  13
R-squared :  0.9624535036571532
P-value : 
chg_oil_spot_WTI_Positive    0.5445
chg_oil_spot_WTI_Negative    0.1598
chg_gdp_us                   0.3382
chg_gdp_china                0.2009
chg_gdp_europe               0.5705
chg_oil_spot_WTI_lag_13      0.8333
chg_gdp_us_lag_13            0.3456
chg_gdp_china_lag_13         0.5664
chg_gdp_europe_lag_13        0.8381
chg_oil_spot_WTI_lag_12      0.9700
chg_gdp_us_lag_12            0.4779
chg_gdp_china_lag_12         0.9802
chg_gdp_europe_lag_12        0.2159
chg_oil_spot_WTI_lag_11      0.7388
chg_gdp_us_lag_11            0.7101
chg_gdp_china_lag_11         0.7611
chg_gdp_europe_lag_11        0.0747
chg_oil_spot_WTI_lag_10      0.5589
chg_gdp_us_lag_10            0.9336
chg_gdp_china_lag_10         0.4443
chg_gdp_europe_lag_10        0.3764
chg_oil_spot_WTI_lag_9       0.6027
chg_gdp_us_lag_9             0.3528
chg_gdp_china_lag_9          0.3532
chg_gdp_europe_lag_9         0.8596
chg_oil_spot_WTI_lag_8       0.7407
chg_gdp_us_lag_8             0.9441
chg_gdp_china_lag_8          0.7472
chg_gdp_europe_lag_8         0.3756
chg_oil_spot_WTI_lag_7       0.3052
chg_gdp_us_lag_7             0.2741
chg_gdp_china_lag_7          0.8713
chg_gdp_europe_lag_7         0.3226
chg_oil_spot_WTI_lag_6       0.1009
chg_gdp_us_lag_6             0.0615
chg_gdp_china_lag_6          0.8985
chg_gdp_europe_lag_6         0.4158
chg_oil_spot_WTI_lag_5       0.4082
chg_gdp_us_lag_5             0.9885
chg_gdp_china_lag_5          0.8569
chg_gdp_europe_lag_5         0.7793
chg_oil_spot_WTI_lag_4       0.1082
chg_gdp_us_lag_4             0.1206
chg_gdp_china_lag_4          0.5418
chg_gdp_europe_lag_4         0.9185
chg_oil_spot_WTI_lag_3       0.7859
chg_gdp_us_lag_3             0.1774
chg_gdp_china_lag_3          0.9364
chg_gdp_europe_lag_3         0.3282
chg_oil_spot_WTI_lag_2       0.0921
chg_gdp_us_lag_2             0.2577
chg_gdp_china_lag_2          0.3708
chg_gdp_europe_lag_2         0.6694
chg_oil_spot_WTI_lag_1       0.3282
chg_gdp_us_lag_1             0.0844
chg_gdp_china_lag_1          0.3346
chg_gdp_europe_lag_1         0.5408
dtype: float64
 
Number of lag :  14
R-squared :  0.9838472113654785
P-value : 
chg_oil_spot_WTI_Positive    0.3446
chg_oil_spot_WTI_Negative    0.7646
chg_gdp_us                   0.2980
chg_gdp_china                0.1453
chg_gdp_europe               0.2118
                              ...  
chg_gdp_europe_lag_2         0.2372
chg_oil_spot_WTI_lag_1       0.4900
chg_gdp_us_lag_1             0.8230
chg_gdp_china_lag_1          0.4432
chg_gdp_europe_lag_1         0.9862
Length: 61, dtype: float64
 
Number of lag :  15
R-squared :  0.9999999750939684
P-value : 
chg_oil_spot_WTI_Positive    0.0000
chg_oil_spot_WTI_Negative    0.0000
chg_gdp_us                   0.0000
chg_gdp_china                0.0000
chg_gdp_europe               0.0004
                              ...  
chg_gdp_europe_lag_2         0.0000
chg_oil_spot_WTI_lag_1       0.0000
chg_gdp_us_lag_1             0.0000
chg_gdp_china_lag_1          0.0000
chg_gdp_europe_lag_1         0.0001
Length: 65, dtype: float64
 
Number of lag :  16
R-squared :  0.9999999888345652
P-value : 
chg_oil_spot_WTI_Positive   NaN
chg_oil_spot_WTI_Negative   NaN
chg_gdp_us                  NaN
chg_gdp_china               NaN
chg_gdp_europe              NaN
                             ..
chg_gdp_europe_lag_2        NaN
chg_oil_spot_WTI_lag_1      NaN
chg_gdp_us_lag_1            NaN
chg_gdp_china_lag_1         NaN
chg_gdp_europe_lag_1        NaN
Length: 69, dtype: float64
 
Number of lag :  17
R-squared :  0.9999999784705177
P-value : 
chg_oil_spot_WTI_Positive   NaN
chg_oil_spot_WTI_Negative   NaN
chg_gdp_us                  NaN
chg_gdp_china               NaN
chg_gdp_europe              NaN
                             ..
chg_gdp_europe_lag_2        NaN
chg_oil_spot_WTI_lag_1      NaN
chg_gdp_us_lag_1            NaN
chg_gdp_china_lag_1         NaN
chg_gdp_europe_lag_1        NaN
Length: 73, dtype: float64
 
Number of lag :  18
R-squared :  0.9999999786134298
P-value : 
chg_oil_spot_WTI_Positive   NaN
chg_oil_spot_WTI_Negative   NaN
chg_gdp_us                  NaN
chg_gdp_china               NaN
chg_gdp_europe              NaN
                             ..
chg_gdp_europe_lag_2        NaN
chg_oil_spot_WTI_lag_1      NaN
chg_gdp_us_lag_1            NaN
chg_gdp_china_lag_1         NaN
chg_gdp_europe_lag_1        NaN
Length: 77, dtype: float64
 
Number of lag :  19
C:\Users\DELL\Anaconda3\lib\site-packages\statsmodels\regression\linear_model.py:1510: RuntimeWarning: divide by zero encountered in double_scalars
  return np.dot(wresid, wresid) / self.df_resid
C:\Users\DELL\Anaconda3\lib\site-packages\statsmodels\regression\linear_model.py:1510: RuntimeWarning: divide by zero encountered in double_scalars
  return np.dot(wresid, wresid) / self.df_resid
C:\Users\DELL\Anaconda3\lib\site-packages\statsmodels\regression\linear_model.py:1510: RuntimeWarning: divide by zero encountered in double_scalars
  return np.dot(wresid, wresid) / self.df_resid
R-squared :  0.9999996728271673
P-value : 
chg_oil_spot_WTI_Positive   NaN
chg_oil_spot_WTI_Negative   NaN
chg_gdp_us                  NaN
chg_gdp_china               NaN
chg_gdp_europe              NaN
                             ..
chg_gdp_europe_lag_2        NaN
chg_oil_spot_WTI_lag_1      NaN
chg_gdp_us_lag_1            NaN
chg_gdp_china_lag_1         NaN
chg_gdp_europe_lag_1        NaN
Length: 81, dtype: float64
 
Number of lag :  20
R-squared :  0.9999999910111339
P-value : 
chg_oil_spot_WTI_Positive   NaN
chg_oil_spot_WTI_Negative   NaN
chg_gdp_us                  NaN
chg_gdp_china               NaN
chg_gdp_europe              NaN
                             ..
chg_gdp_europe_lag_2        NaN
chg_oil_spot_WTI_lag_1      NaN
chg_gdp_us_lag_1            NaN
chg_gdp_china_lag_1         NaN
chg_gdp_europe_lag_1        NaN
Length: 85, dtype: float64
 
C:\Users\DELL\Anaconda3\lib\site-packages\statsmodels\regression\linear_model.py:1510: RuntimeWarning: divide by zero encountered in double_scalars
  return np.dot(wresid, wresid) / self.df_resid
C:\Users\DELL\Anaconda3\lib\site-packages\statsmodels\regression\linear_model.py:1510: RuntimeWarning: divide by zero encountered in double_scalars
  return np.dot(wresid, wresid) / self.df_resid
Up to lag 8 gives the best prediction on Change in oil price
Regression only oil price to CO2

3.3 Cointegration -- VECM

In [127]:
%matplotlib inline
import numpy as np
from matplotlib import pyplot as plt
from statsmodels.tsa.vector_ar.vecm import *
import pandas
In [128]:
quick_analysis_ln = np.log(quick_anaysis[['oil_spot_WTI','gdp_us', 'gdp_china', 'gdp_europe','Celsius', 'CO2_Concentration']])
In [129]:
lag_order = select_order(data=quick_analysis_ln, maxlags=10, deterministic="ci", seasons=4)
lag_order.summary()
C:\Users\DELL\Anaconda3\lib\site-packages\statsmodels\tsa\base\tsa_model.py:221: ValueWarning: An unsupported index was provided and will be ignored when e.g. forecasting.
  ' ignored when e.g. forecasting.', ValueWarning)
C:\Users\DELL\Anaconda3\lib\site-packages\statsmodels\tsa\base\tsa_model.py:221: ValueWarning: An unsupported index was provided and will be ignored when e.g. forecasting.
  ' ignored when e.g. forecasting.', ValueWarning)
C:\Users\DELL\Anaconda3\lib\site-packages\statsmodels\tsa\base\tsa_model.py:221: ValueWarning: An unsupported index was provided and will be ignored when e.g. forecasting.
  ' ignored when e.g. forecasting.', ValueWarning)
C:\Users\DELL\Anaconda3\lib\site-packages\statsmodels\tsa\base\tsa_model.py:221: ValueWarning: An unsupported index was provided and will be ignored when e.g. forecasting.
  ' ignored when e.g. forecasting.', ValueWarning)
C:\Users\DELL\Anaconda3\lib\site-packages\statsmodels\tsa\base\tsa_model.py:221: ValueWarning: An unsupported index was provided and will be ignored when e.g. forecasting.
  ' ignored when e.g. forecasting.', ValueWarning)
C:\Users\DELL\Anaconda3\lib\site-packages\statsmodels\tsa\base\tsa_model.py:221: ValueWarning: An unsupported index was provided and will be ignored when e.g. forecasting.
  ' ignored when e.g. forecasting.', ValueWarning)
C:\Users\DELL\Anaconda3\lib\site-packages\statsmodels\tsa\base\tsa_model.py:221: ValueWarning: An unsupported index was provided and will be ignored when e.g. forecasting.
  ' ignored when e.g. forecasting.', ValueWarning)
C:\Users\DELL\Anaconda3\lib\site-packages\statsmodels\tsa\base\tsa_model.py:221: ValueWarning: An unsupported index was provided and will be ignored when e.g. forecasting.
  ' ignored when e.g. forecasting.', ValueWarning)
C:\Users\DELL\Anaconda3\lib\site-packages\statsmodels\tsa\base\tsa_model.py:221: ValueWarning: An unsupported index was provided and will be ignored when e.g. forecasting.
  ' ignored when e.g. forecasting.', ValueWarning)
C:\Users\DELL\Anaconda3\lib\site-packages\statsmodels\tsa\base\tsa_model.py:221: ValueWarning: An unsupported index was provided and will be ignored when e.g. forecasting.
  ' ignored when e.g. forecasting.', ValueWarning)
C:\Users\DELL\Anaconda3\lib\site-packages\statsmodels\tsa\base\tsa_model.py:221: ValueWarning: An unsupported index was provided and will be ignored when e.g. forecasting.
  ' ignored when e.g. forecasting.', ValueWarning)
Out[129]:
VECM Order Selection (* highlights the minimums)
AIC BIC FPE HQIC
0 -47.37 -45.51* 2.701e-21 -46.62*
1 -47.36 -44.49 2.775e-21 -46.21
2 -47.32 -43.44 3.017e-21 -45.76
3 -47.54 -42.64 2.643e-21 -45.56
4 -48.22 -42.30 1.517e-21* -45.83
5 -47.93 -41.00 2.443e-21 -45.14
6 -47.87 -39.93 3.410e-21 -44.67
7 -48.65 -39.70 2.300e-21 -45.05
8 -49.41 -39.44 1.901e-21 -45.39
9 -49.91 -38.94 2.574e-21 -45.49
10 -51.27* -39.28 2.261e-21 -46.44
In [130]:
rank_test = select_coint_rank(quick_analysis_ln, 0, 3, method="trace",signif=0.05)
rank_test.rank

model = VECM(quick_analysis_ln, deterministic="ci", seasons=4,
             k_ar_diff=lag_order.aic,  # =3
             coint_rank=rank_test.rank)  # =1
C:\Users\DELL\Anaconda3\lib\site-packages\statsmodels\tsa\base\tsa_model.py:221: ValueWarning: An unsupported index was provided and will be ignored when e.g. forecasting.
  ' ignored when e.g. forecasting.', ValueWarning)
In [131]:
vecm_res = model.fit()
vecm_res.summary()
Out[131]:
Det. terms outside the coint. relation & lagged endog. parameters for equation oil_spot_WTI
coef std err z P>|z| [0.025 0.975]
season1 0.2428 0.377 0.644 0.520 -0.497 0.982
season2 -0.2548 0.569 -0.448 0.654 -1.371 0.861
season3 -0.8880 0.386 -2.302 0.021 -1.644 -0.132
L1.oil_spot_WTI -0.6636 0.250 -2.652 0.008 -1.154 -0.173
L1.gdp_us 8.7923 3.858 2.279 0.023 1.230 16.355
L1.gdp_china 2.3442 1.581 1.482 0.138 -0.755 5.444
L1.gdp_europe -0.0767 2.420 -0.032 0.975 -4.820 4.666
L1.Celsius -2.0506 0.352 -5.825 0.000 -2.741 -1.361
L1.CO2_Concentration -52.9986 26.469 -2.002 0.045 -104.877 -1.120
L2.oil_spot_WTI -0.4546 0.251 -1.810 0.070 -0.947 0.038
L2.gdp_us 7.7618 4.009 1.936 0.053 -0.096 15.619
L2.gdp_china 0.2273 1.843 0.123 0.902 -3.384 3.839
L2.gdp_europe -13.0255 2.402 -5.423 0.000 -17.733 -8.318
L2.Celsius -1.4837 0.344 -4.316 0.000 -2.158 -0.810
L2.CO2_Concentration -15.4504 24.016 -0.643 0.520 -62.522 31.621
L3.oil_spot_WTI -0.2429 0.233 -1.041 0.298 -0.700 0.214
L3.gdp_us -2.6765 3.367 -0.795 0.427 -9.275 3.922
L3.gdp_china 2.4694 1.750 1.411 0.158 -0.960 5.899
L3.gdp_europe -1.8119 2.229 -0.813 0.416 -6.181 2.557
L3.Celsius -1.5485 0.350 -4.424 0.000 -2.234 -0.862
L3.CO2_Concentration -18.4504 23.951 -0.770 0.441 -65.393 28.492
L4.oil_spot_WTI -0.4191 0.197 -2.122 0.034 -0.806 -0.032
L4.gdp_us 6.8235 3.192 2.138 0.033 0.567 13.080
L4.gdp_china -0.4412 1.717 -0.257 0.797 -3.806 2.923
L4.gdp_europe -2.3364 2.108 -1.108 0.268 -6.468 1.795
L4.Celsius -1.1881 0.316 -3.764 0.000 -1.807 -0.569
L4.CO2_Concentration -0.9616 22.849 -0.042 0.966 -45.745 43.822
L5.oil_spot_WTI -0.1196 0.195 -0.613 0.540 -0.502 0.263
L5.gdp_us 3.2562 3.456 0.942 0.346 -3.517 10.030
L5.gdp_china -0.1972 1.595 -0.124 0.902 -3.323 2.928
L5.gdp_europe -8.2971 2.229 -3.722 0.000 -12.666 -3.928
L5.Celsius -1.2941 0.246 -5.265 0.000 -1.776 -0.812
L5.CO2_Concentration -24.7843 22.226 -1.115 0.265 -68.346 18.778
L6.oil_spot_WTI -0.1891 0.143 -1.319 0.187 -0.470 0.092
L6.gdp_us 5.5728 3.759 1.482 0.138 -1.796 12.941
L6.gdp_china 1.4853 1.780 0.835 0.404 -2.003 4.973
L6.gdp_europe 1.8642 2.703 0.690 0.490 -3.433 7.161
L6.Celsius -0.7770 0.199 -3.896 0.000 -1.168 -0.386
L6.CO2_Concentration 6.8187 19.042 0.358 0.720 -30.503 44.140
L7.oil_spot_WTI 0.1911 0.150 1.276 0.202 -0.102 0.485
L7.gdp_us 9.3957 3.516 2.673 0.008 2.505 16.286
L7.gdp_china -2.5120 1.731 -1.451 0.147 -5.905 0.881
L7.gdp_europe -14.4788 2.644 -5.476 0.000 -19.661 -9.297
L7.Celsius -0.8988 0.183 -4.925 0.000 -1.257 -0.541
L7.CO2_Concentration -24.4529 15.100 -1.619 0.105 -54.048 5.142
L8.oil_spot_WTI -0.0770 0.142 -0.541 0.588 -0.356 0.202
L8.gdp_us 16.1469 3.776 4.276 0.000 8.746 23.547
L8.gdp_china 1.4969 1.549 0.966 0.334 -1.540 4.534
L8.gdp_europe -2.5732 2.469 -1.042 0.297 -7.412 2.265
L8.Celsius -0.4746 0.169 -2.809 0.005 -0.806 -0.143
L8.CO2_Concentration 8.3277 13.943 0.597 0.550 -19.000 35.656
L9.oil_spot_WTI -0.0842 0.137 -0.613 0.540 -0.353 0.185
L9.gdp_us 6.2820 3.967 1.584 0.113 -1.493 14.057
L9.gdp_china -1.0228 1.267 -0.807 0.419 -3.505 1.460
L9.gdp_europe -10.8311 2.430 -4.458 0.000 -15.593 -6.069
L9.Celsius -0.3563 0.132 -2.707 0.007 -0.614 -0.098
L9.CO2_Concentration -14.3136 11.477 -1.247 0.212 -36.809 8.182
L10.oil_spot_WTI 0.1026 0.119 0.865 0.387 -0.130 0.335
L10.gdp_us 22.9785 4.352 5.281 0.000 14.450 31.507
L10.gdp_china -0.9541 1.141 -0.836 0.403 -3.190 1.282
L10.gdp_europe -2.8943 2.010 -1.440 0.150 -6.833 1.045
L10.Celsius -0.4454 0.112 -3.992 0.000 -0.664 -0.227
L10.CO2_Concentration 20.5130 11.257 1.822 0.068 -1.551 42.577
Det. terms outside the coint. relation & lagged endog. parameters for equation gdp_us
coef std err z P>|z| [0.025 0.975]
season1 -0.0311 0.012 -2.500 0.012 -0.055 -0.007
season2 -0.0309 0.019 -1.648 0.099 -0.068 0.006
season3 -0.0183 0.013 -1.441 0.149 -0.043 0.007
L1.oil_spot_WTI -0.0332 0.008 -4.026 0.000 -0.049 -0.017
L1.gdp_us 0.4186 0.127 3.292 0.001 0.169 0.668
L1.gdp_china 0.1221 0.052 2.342 0.019 0.020 0.224
L1.gdp_europe -0.0356 0.080 -0.447 0.655 -0.192 0.121
L1.Celsius -0.0683 0.012 -5.886 0.000 -0.091 -0.046
L1.CO2_Concentration -2.8586 0.872 -3.277 0.001 -4.568 -1.149
L2.oil_spot_WTI -0.0258 0.008 -3.118 0.002 -0.042 -0.010
L2.gdp_us 0.2777 0.132 2.102 0.036 0.019 0.537
L2.gdp_china -0.1687 0.061 -2.777 0.005 -0.288 -0.050
L2.gdp_europe -0.1457 0.079 -1.841 0.066 -0.301 0.009
L2.Celsius -0.0516 0.011 -4.553 0.000 -0.074 -0.029
L2.CO2_Concentration -2.3593 0.792 -2.981 0.003 -3.911 -0.808
L3.oil_spot_WTI -0.0150 0.008 -1.957 0.050 -0.030 2.17e-05
L3.gdp_us 0.0392 0.111 0.353 0.724 -0.178 0.257
L3.gdp_china 0.1201 0.058 2.083 0.037 0.007 0.233
L3.gdp_europe 0.0709 0.073 0.965 0.335 -0.073 0.215
L3.Celsius -0.0516 0.012 -4.476 0.000 -0.074 -0.029
L3.CO2_Concentration -2.1343 0.789 -2.704 0.007 -3.681 -0.587
L4.oil_spot_WTI -0.0118 0.007 -1.815 0.069 -0.025 0.001
L4.gdp_us -0.0612 0.105 -0.581 0.561 -0.267 0.145
L4.gdp_china 0.0108 0.057 0.191 0.848 -0.100 0.122
L4.gdp_europe -0.2390 0.069 -3.441 0.001 -0.375 -0.103
L4.Celsius -0.0366 0.010 -3.520 0.000 -0.057 -0.016
L4.CO2_Concentration -1.6948 0.753 -2.251 0.024 -3.171 -0.219
L5.oil_spot_WTI -0.0045 0.006 -0.705 0.481 -0.017 0.008
L5.gdp_us 0.3545 0.114 3.113 0.002 0.131 0.578
L5.gdp_china -0.1162 0.053 -2.211 0.027 -0.219 -0.013
L5.gdp_europe -0.2242 0.073 -3.051 0.002 -0.368 -0.080
L5.Celsius -0.0311 0.008 -3.842 0.000 -0.047 -0.015
L5.CO2_Concentration -0.7809 0.732 -1.066 0.286 -2.217 0.655
L6.oil_spot_WTI -0.0168 0.005 -3.565 0.000 -0.026 -0.008
L6.gdp_us 0.4283 0.124 3.457 0.001 0.185 0.671
L6.gdp_china 0.1527 0.059 2.604 0.009 0.038 0.268
L6.gdp_europe -0.1148 0.089 -1.289 0.197 -0.289 0.060
L6.Celsius -0.0237 0.007 -3.603 0.000 -0.037 -0.011
L6.CO2_Concentration -0.1611 0.628 -0.257 0.797 -1.391 1.069
L7.oil_spot_WTI -0.0103 0.005 -2.095 0.036 -0.020 -0.001
L7.gdp_us 0.4701 0.116 4.057 0.000 0.243 0.697
L7.gdp_china -0.1004 0.057 -1.759 0.079 -0.212 0.011
L7.gdp_europe -0.1871 0.087 -2.147 0.032 -0.358 -0.016
L7.Celsius -0.0312 0.006 -5.195 0.000 -0.043 -0.019
L7.CO2_Concentration -0.5844 0.498 -1.174 0.240 -1.560 0.391
L8.oil_spot_WTI 0.0005 0.005 0.109 0.913 -0.009 0.010
L8.gdp_us 0.0910 0.124 0.731 0.465 -0.153 0.335
L8.gdp_china -0.0091 0.051 -0.177 0.859 -0.109 0.091
L8.gdp_europe -0.0001 0.081 -0.002 0.999 -0.160 0.159
L8.Celsius -0.0142 0.006 -2.549 0.011 -0.025 -0.003
L8.CO2_Concentration 0.3074 0.460 0.669 0.504 -0.593 1.208
L9.oil_spot_WTI -0.0007 0.005 -0.144 0.885 -0.010 0.008
L9.gdp_us 0.3198 0.131 2.446 0.014 0.064 0.576
L9.gdp_china -0.0106 0.042 -0.253 0.800 -0.092 0.071
L9.gdp_europe -0.2801 0.080 -3.497 0.000 -0.437 -0.123
L9.Celsius -0.0170 0.004 -3.917 0.000 -0.025 -0.008
L9.CO2_Concentration -0.0898 0.378 -0.237 0.812 -0.831 0.652
L10.oil_spot_WTI 0.0046 0.004 1.171 0.242 -0.003 0.012
L10.gdp_us 0.2685 0.143 1.872 0.061 -0.013 0.550
L10.gdp_china 0.0483 0.038 1.286 0.199 -0.025 0.122
L10.gdp_europe -0.1011 0.066 -1.526 0.127 -0.231 0.029
L10.Celsius -0.0089 0.004 -2.421 0.015 -0.016 -0.002
L10.CO2_Concentration 0.5198 0.371 1.401 0.161 -0.207 1.247
Det. terms outside the coint. relation & lagged endog. parameters for equation gdp_china
coef std err z P>|z| [0.025 0.975]
season1 0.1337 0.020 6.765 0.000 0.095 0.172
season2 0.0731 0.030 2.452 0.014 0.015 0.132
season3 -0.0321 0.020 -1.588 0.112 -0.072 0.008
L1.oil_spot_WTI -0.1116 0.013 -8.516 0.000 -0.137 -0.086
L1.gdp_us 0.0599 0.202 0.296 0.767 -0.336 0.456
L1.gdp_china 0.6168 0.083 7.448 0.000 0.455 0.779
L1.gdp_europe 0.6759 0.127 5.333 0.000 0.428 0.924
L1.Celsius -0.1839 0.018 -9.974 0.000 -0.220 -0.148
L1.CO2_Concentration -13.4771 1.386 -9.722 0.000 -16.194 -10.760
L2.oil_spot_WTI -0.1118 0.013 -8.499 0.000 -0.138 -0.086
L2.gdp_us 0.4608 0.210 2.194 0.028 0.049 0.872
L2.gdp_china 0.1938 0.097 2.008 0.045 0.005 0.383
L2.gdp_europe -0.8955 0.126 -7.119 0.000 -1.142 -0.649
L2.Celsius -0.1364 0.018 -7.573 0.000 -0.172 -0.101
L2.CO2_Concentration -9.6919 1.258 -7.705 0.000 -12.157 -7.227
L3.oil_spot_WTI -0.0826 0.012 -6.759 0.000 -0.107 -0.059
L3.gdp_us 0.3155 0.176 1.790 0.074 -0.030 0.661
L3.gdp_china -0.1678 0.092 -1.831 0.067 -0.347 0.012
L3.gdp_europe 0.2327 0.117 1.993 0.046 0.004 0.461
L3.Celsius -0.1435 0.018 -7.830 0.000 -0.179 -0.108
L3.CO2_Concentration -9.1091 1.254 -7.262 0.000 -11.568 -6.651
L4.oil_spot_WTI -0.0964 0.010 -9.316 0.000 -0.117 -0.076
L4.gdp_us -0.4285 0.167 -2.563 0.010 -0.756 -0.101
L4.gdp_china 1.0047 0.090 11.175 0.000 0.828 1.181
L4.gdp_europe 0.3147 0.110 2.850 0.004 0.098 0.531
L4.Celsius -0.1219 0.017 -7.370 0.000 -0.154 -0.089
L4.CO2_Concentration -8.2571 1.197 -6.900 0.000 -10.603 -5.912
L5.oil_spot_WTI -0.0782 0.010 -7.648 0.000 -0.098 -0.058
L5.gdp_us 0.2587 0.181 1.429 0.153 -0.096 0.613
L5.gdp_china -0.3406 0.084 -4.078 0.000 -0.504 -0.177
L5.gdp_europe -0.6916 0.117 -5.924 0.000 -0.920 -0.463
L5.Celsius -0.1116 0.013 -8.670 0.000 -0.137 -0.086
L5.CO2_Concentration -7.9675 1.164 -6.845 0.000 -10.249 -5.686
L6.oil_spot_WTI -0.0360 0.008 -4.802 0.000 -0.051 -0.021
L6.gdp_us 0.5835 0.197 2.963 0.003 0.198 0.969
L6.gdp_china 0.0825 0.093 0.886 0.376 -0.100 0.265
L6.gdp_europe 0.6698 0.142 4.732 0.000 0.392 0.947
L6.Celsius -0.0863 0.010 -8.262 0.000 -0.107 -0.066
L6.CO2_Concentration -3.2992 0.997 -3.308 0.001 -5.254 -1.345
L7.oil_spot_WTI -0.0420 0.008 -5.354 0.000 -0.057 -0.027
L7.gdp_us -0.1106 0.184 -0.601 0.548 -0.471 0.250
L7.gdp_china 0.1393 0.091 1.537 0.124 -0.038 0.317
L7.gdp_europe -0.8238 0.138 -5.950 0.000 -1.095 -0.552
L7.Celsius -0.0867 0.010 -9.066 0.000 -0.105 -0.068
L7.CO2_Concentration -5.9528 0.791 -7.527 0.000 -7.503 -4.403
L8.oil_spot_WTI -0.0419 0.007 -5.615 0.000 -0.056 -0.027
L8.gdp_us 0.9254 0.198 4.680 0.000 0.538 1.313
L8.gdp_china -0.0449 0.081 -0.553 0.580 -0.204 0.114
L8.gdp_europe -0.3283 0.129 -2.539 0.011 -0.582 -0.075
L8.Celsius -0.0599 0.009 -6.775 0.000 -0.077 -0.043
L8.CO2_Concentration -2.9527 0.730 -4.043 0.000 -4.384 -1.521
L9.oil_spot_WTI -0.0613 0.007 -8.521 0.000 -0.075 -0.047
L9.gdp_us 1.1132 0.208 5.358 0.000 0.706 1.520
L9.gdp_china 0.2153 0.066 3.246 0.001 0.085 0.345
L9.gdp_europe -0.2900 0.127 -2.279 0.023 -0.539 -0.041
L9.Celsius -0.0421 0.007 -6.102 0.000 -0.056 -0.029
L9.CO2_Concentration -3.7100 0.601 -6.172 0.000 -4.888 -2.532
L10.oil_spot_WTI -0.0120 0.006 -1.939 0.052 -0.024 0.000
L10.gdp_us 0.7870 0.228 3.453 0.001 0.340 1.234
L10.gdp_china -0.0325 0.060 -0.544 0.586 -0.150 0.085
L10.gdp_europe -0.3196 0.105 -3.036 0.002 -0.526 -0.113
L10.Celsius -0.0632 0.006 -10.814 0.000 -0.075 -0.052
L10.CO2_Concentration -3.8074 0.590 -6.458 0.000 -4.963 -2.652
Det. terms outside the coint. relation & lagged endog. parameters for equation gdp_europe
coef std err z P>|z| [0.025 0.975]
season1 0.0115 0.019 0.606 0.544 -0.026 0.048
season2 0.0459 0.029 1.609 0.108 -0.010 0.102
season3 0.0151 0.019 0.784 0.433 -0.023 0.053
L1.oil_spot_WTI -0.0420 0.013 -3.349 0.001 -0.067 -0.017
L1.gdp_us 0.0835 0.193 0.432 0.666 -0.295 0.462
L1.gdp_china 0.2822 0.079 3.563 0.000 0.127 0.437
L1.gdp_europe 0.4212 0.121 3.475 0.001 0.184 0.659
L1.Celsius -0.0333 0.018 -1.887 0.059 -0.068 0.001
L1.CO2_Concentration -4.5951 1.326 -3.466 0.001 -7.194 -1.996
L2.oil_spot_WTI -0.0419 0.013 -3.335 0.001 -0.067 -0.017
L2.gdp_us 0.2835 0.201 1.412 0.158 -0.110 0.677
L2.gdp_china -0.0869 0.092 -0.941 0.347 -0.268 0.094
L2.gdp_europe -0.0782 0.120 -0.650 0.515 -0.314 0.158
L2.Celsius -0.0202 0.017 -1.175 0.240 -0.054 0.014
L2.CO2_Concentration -4.5489 1.203 -3.781 0.000 -6.907 -2.191
L3.oil_spot_WTI -0.0279 0.012 -2.391 0.017 -0.051 -0.005
L3.gdp_us 0.4364 0.169 2.588 0.010 0.106 0.767
L3.gdp_china -0.0907 0.088 -1.035 0.301 -0.262 0.081
L3.gdp_europe 0.0394 0.112 0.353 0.724 -0.179 0.258
L3.Celsius -0.0093 0.018 -0.532 0.595 -0.044 0.025
L3.CO2_Concentration -4.2482 1.200 -3.541 0.000 -6.600 -1.897
L4.oil_spot_WTI -0.0179 0.010 -1.810 0.070 -0.037 0.001
L4.gdp_us -0.3257 0.160 -2.037 0.042 -0.639 -0.012
L4.gdp_china 0.2708 0.086 3.149 0.002 0.102 0.439
L4.gdp_europe 0.1245 0.106 1.179 0.238 -0.082 0.331
L4.Celsius 0.0019 0.016 0.122 0.903 -0.029 0.033
L4.CO2_Concentration -3.2805 1.145 -2.866 0.004 -5.524 -1.037
L5.oil_spot_WTI -0.0192 0.010 -1.962 0.050 -0.038 -1.5e-05
L5.gdp_us 0.0056 0.173 0.033 0.974 -0.334 0.345
L5.gdp_china -0.1521 0.080 -1.904 0.057 -0.309 0.005
L5.gdp_europe -0.6511 0.112 -5.831 0.000 -0.870 -0.432
L5.Celsius -0.0072 0.012 -0.584 0.559 -0.031 0.017
L5.CO2_Concentration -3.2704 1.113 -2.937 0.003 -5.452 -1.088
L6.oil_spot_WTI -0.0188 0.007 -2.617 0.009 -0.033 -0.005
L6.gdp_us 0.2372 0.188 1.259 0.208 -0.132 0.606
L6.gdp_china -0.0017 0.089 -0.019 0.985 -0.176 0.173
L6.gdp_europe 0.3407 0.135 2.517 0.012 0.075 0.606
L6.Celsius 0.0012 0.010 0.123 0.902 -0.018 0.021
L6.CO2_Concentration -1.3515 0.954 -1.417 0.157 -3.221 0.518
L7.oil_spot_WTI -0.0296 0.008 -3.951 0.000 -0.044 -0.015
L7.gdp_us 0.0219 0.176 0.124 0.901 -0.323 0.367
L7.gdp_china 0.1088 0.087 1.254 0.210 -0.061 0.279
L7.gdp_europe 0.0399 0.132 0.301 0.763 -0.220 0.299
L7.Celsius -0.0056 0.009 -0.607 0.544 -0.023 0.012
L7.CO2_Concentration -1.3799 0.756 -1.824 0.068 -2.862 0.103
L8.oil_spot_WTI -0.0025 0.007 -0.346 0.729 -0.016 0.012
L8.gdp_us 0.2482 0.189 1.312 0.189 -0.122 0.619
L8.gdp_china -0.2254 0.078 -2.904 0.004 -0.378 -0.073
L8.gdp_europe 0.0332 0.124 0.269 0.788 -0.209 0.276
L8.Celsius -0.0121 0.008 -1.435 0.151 -0.029 0.004
L8.CO2_Concentration -0.7052 0.698 -1.010 0.313 -2.074 0.664
L9.oil_spot_WTI -0.0090 0.007 -1.310 0.190 -0.022 0.004
L9.gdp_us 0.0664 0.199 0.334 0.738 -0.323 0.456
L9.gdp_china -0.0803 0.063 -1.265 0.206 -0.205 0.044
L9.gdp_europe 0.0661 0.122 0.543 0.587 -0.172 0.305
L9.Celsius 0.0028 0.007 0.420 0.674 -0.010 0.016
L9.CO2_Concentration -1.1407 0.575 -1.984 0.047 -2.268 -0.014
L10.oil_spot_WTI -0.0084 0.006 -1.419 0.156 -0.020 0.003
L10.gdp_us -0.1638 0.218 -0.752 0.452 -0.591 0.263
L10.gdp_china 0.1073 0.057 1.878 0.060 -0.005 0.219
L10.gdp_europe -0.1095 0.101 -1.088 0.277 -0.307 0.088
L10.Celsius -0.0110 0.006 -1.970 0.049 -0.022 -5.83e-05
L10.CO2_Concentration -1.9300 0.564 -3.423 0.001 -3.035 -0.825
Det. terms outside the coint. relation & lagged endog. parameters for equation Celsius
coef std err z P>|z| [0.025 0.975]
season1 0.7673 0.463 1.658 0.097 -0.140 1.674
season2 0.4405 0.698 0.631 0.528 -0.928 1.809
season3 0.6887 0.473 1.456 0.145 -0.239 1.616
L1.oil_spot_WTI -0.5566 0.307 -1.814 0.070 -1.158 0.045
L1.gdp_us -7.5524 4.732 -1.596 0.110 -16.826 1.722
L1.gdp_china -0.3999 1.939 -0.206 0.837 -4.201 3.401
L1.gdp_europe 6.3037 2.968 2.124 0.034 0.487 12.120
L1.Celsius -0.1889 0.432 -0.437 0.662 -1.035 0.657
L1.CO2_Concentration -56.6413 32.460 -1.745 0.081 -120.262 6.979
L2.oil_spot_WTI -0.4782 0.308 -1.553 0.120 -1.082 0.125
L2.gdp_us 2.4660 4.916 0.502 0.616 -7.170 12.102
L2.gdp_china -0.5415 2.260 -0.240 0.811 -4.971 3.888
L2.gdp_europe -2.5321 2.946 -0.860 0.390 -8.305 3.241
L2.Celsius -0.1206 0.422 -0.286 0.775 -0.947 0.706
L2.CO2_Concentration -58.7637 29.452 -1.995 0.046 -116.488 -1.039
L3.oil_spot_WTI -0.6171 0.286 -2.157 0.031 -1.178 -0.056
L3.gdp_us -3.1139 4.128 -0.754 0.451 -11.206 4.978
L3.gdp_china -1.1589 2.146 -0.540 0.589 -5.365 3.047
L3.gdp_europe 8.9590 2.734 3.277 0.001 3.601 14.317
L3.Celsius -0.0970 0.429 -0.226 0.821 -0.938 0.744
L3.CO2_Concentration -61.1751 29.371 -2.083 0.037 -118.741 -3.609
L4.oil_spot_WTI -0.4985 0.242 -2.059 0.040 -0.973 -0.024
L4.gdp_us -6.7995 3.915 -1.737 0.082 -14.472 0.873
L4.gdp_china 0.8253 2.105 0.392 0.695 -3.301 4.951
L4.gdp_europe 0.2798 2.585 0.108 0.914 -4.786 5.346
L4.Celsius -0.2925 0.387 -0.756 0.450 -1.051 0.466
L4.CO2_Concentration -91.7386 28.020 -3.274 0.001 -146.658 -36.819
L5.oil_spot_WTI -0.6625 0.239 -2.767 0.006 -1.132 -0.193
L5.gdp_us 0.3216 4.238 0.076 0.940 -7.985 8.628
L5.gdp_china 2.1353 1.956 1.092 0.275 -1.698 5.968
L5.gdp_europe 4.3401 2.734 1.588 0.112 -1.018 9.698
L5.Celsius 0.0696 0.301 0.231 0.817 -0.521 0.660
L5.CO2_Concentration -63.2277 27.256 -2.320 0.020 -116.649 -9.807
L6.oil_spot_WTI -0.2385 0.176 -1.357 0.175 -0.583 0.106
L6.gdp_us -1.1466 4.610 -0.249 0.804 -10.183 7.889
L6.gdp_china 2.9709 2.182 1.361 0.173 -1.306 7.248
L6.gdp_europe -3.8948 3.314 -1.175 0.240 -10.391 2.601
L6.Celsius -0.0369 0.245 -0.151 0.880 -0.516 0.443
L6.CO2_Concentration -41.6263 23.352 -1.783 0.075 -87.395 4.142
L7.oil_spot_WTI -0.3160 0.184 -1.721 0.085 -0.676 0.044
L7.gdp_us 2.3691 4.311 0.550 0.583 -6.081 10.819
L7.gdp_china 2.7316 2.123 1.287 0.198 -1.429 6.893
L7.gdp_europe 4.1287 3.242 1.273 0.203 -2.226 10.483
L7.Celsius 0.1734 0.224 0.775 0.439 -0.265 0.612
L7.CO2_Concentration -25.7408 18.517 -1.390 0.165 -62.034 10.553
L8.oil_spot_WTI -0.4369 0.175 -2.503 0.012 -0.779 -0.095
L8.gdp_us -11.3854 4.630 -2.459 0.014 -20.461 -2.310
L8.gdp_china -2.6869 1.900 -1.414 0.157 -6.411 1.037
L8.gdp_europe 3.9480 3.027 1.304 0.192 -1.985 9.881
L8.Celsius 0.0740 0.207 0.357 0.721 -0.332 0.480
L8.CO2_Concentration -25.5801 17.099 -1.496 0.135 -59.093 7.933
L9.oil_spot_WTI -0.4118 0.168 -2.446 0.014 -0.742 -0.082
L9.gdp_us 1.4315 4.865 0.294 0.769 -8.103 10.966
L9.gdp_china -0.1998 1.553 -0.129 0.898 -3.244 2.845
L9.gdp_europe 6.6457 2.980 2.230 0.026 0.806 12.486
L9.Celsius -0.2971 0.161 -1.841 0.066 -0.613 0.019
L9.CO2_Concentration 0.3053 14.075 0.022 0.983 -27.281 27.892
L10.oil_spot_WTI -0.1327 0.145 -0.912 0.362 -0.418 0.152
L10.gdp_us -12.0317 5.336 -2.255 0.024 -22.491 -1.572
L10.gdp_china -0.9098 1.399 -0.650 0.515 -3.652 1.832
L10.gdp_europe 0.6064 2.465 0.246 0.806 -4.224 5.437
L10.Celsius -0.4556 0.137 -3.330 0.001 -0.724 -0.187
L10.CO2_Concentration -27.4955 13.805 -1.992 0.046 -54.553 -0.438
Det. terms outside the coint. relation & lagged endog. parameters for equation CO2_Concentration
coef std err z P>|z| [0.025 0.975]
season1 0.0167 0.004 4.326 0.000 0.009 0.024
season2 -0.0093 0.006 -1.602 0.109 -0.021 0.002
season3 -0.0184 0.004 -4.656 0.000 -0.026 -0.011
L1.oil_spot_WTI -0.0033 0.003 -1.307 0.191 -0.008 0.002
L1.gdp_us 0.0321 0.040 0.813 0.416 -0.045 0.110
L1.gdp_china 0.0408 0.016 2.520 0.012 0.009 0.073
L1.gdp_europe -0.0033 0.025 -0.134 0.894 -0.052 0.045
L1.Celsius 0.0030 0.004 0.838 0.402 -0.004 0.010
L1.CO2_Concentration -1.2053 0.271 -4.447 0.000 -1.737 -0.674
L2.oil_spot_WTI -0.0036 0.003 -1.419 0.156 -0.009 0.001
L2.gdp_us 0.1548 0.041 3.771 0.000 0.074 0.235
L2.gdp_china -0.0640 0.019 -3.392 0.001 -0.101 -0.027
L2.gdp_europe -0.1114 0.025 -4.530 0.000 -0.160 -0.063
L2.Celsius 0.0089 0.004 2.538 0.011 0.002 0.016
L2.CO2_Concentration -0.8023 0.246 -3.262 0.001 -1.284 -0.320
L3.oil_spot_WTI -0.0051 0.002 -2.141 0.032 -0.010 -0.000
L3.gdp_us -0.0119 0.034 -0.344 0.731 -0.079 0.056
L3.gdp_china 0.0480 0.018 2.677 0.007 0.013 0.083
L3.gdp_europe 0.0730 0.023 3.197 0.001 0.028 0.118
L3.Celsius 0.0032 0.004 0.890 0.373 -0.004 0.010
L3.CO2_Concentration -0.7064 0.245 -2.881 0.004 -1.187 -0.226
L4.oil_spot_WTI -0.0115 0.002 -5.703 0.000 -0.015 -0.008
L4.gdp_us 0.0013 0.033 0.039 0.969 -0.063 0.065
L4.gdp_china 0.0470 0.018 2.673 0.008 0.013 0.081
L4.gdp_europe 0.0432 0.022 2.000 0.045 0.001 0.085
L4.Celsius 0.0006 0.003 0.174 0.862 -0.006 0.007
L4.CO2_Concentration -0.7573 0.234 -3.237 0.001 -1.216 -0.299
L5.oil_spot_WTI -0.0051 0.002 -2.538 0.011 -0.009 -0.001
L5.gdp_us 0.0069 0.035 0.195 0.846 -0.062 0.076
L5.gdp_china -0.0470 0.016 -2.877 0.004 -0.079 -0.015
L5.gdp_europe 0.0089 0.023 0.391 0.696 -0.036 0.054
L5.Celsius 0.0004 0.003 0.150 0.880 -0.005 0.005
L5.CO2_Concentration -0.5852 0.228 -2.571 0.010 -1.031 -0.139
L6.oil_spot_WTI -0.0044 0.001 -2.994 0.003 -0.007 -0.002
L6.gdp_us -0.0398 0.038 -1.035 0.301 -0.115 0.036
L6.gdp_china 0.0589 0.018 3.232 0.001 0.023 0.095
L6.gdp_europe 0.0844 0.028 3.049 0.002 0.030 0.139
L6.Celsius 0.0019 0.002 0.929 0.353 -0.002 0.006
L6.CO2_Concentration -0.1019 0.195 -0.523 0.601 -0.484 0.280
L7.oil_spot_WTI -0.0021 0.002 -1.378 0.168 -0.005 0.001
L7.gdp_us -0.1220 0.036 -3.389 0.001 -0.193 -0.051
L7.gdp_china -0.0206 0.018 -1.160 0.246 -0.055 0.014
L7.gdp_europe -0.0092 0.027 -0.339 0.735 -0.062 0.044
L7.Celsius -0.0006 0.002 -0.331 0.740 -0.004 0.003
L7.CO2_Concentration -0.2474 0.155 -1.600 0.110 -0.550 0.056
L8.oil_spot_WTI -0.0054 0.001 -3.698 0.000 -0.008 -0.003
L8.gdp_us -0.0034 0.039 -0.088 0.930 -0.079 0.072
L8.gdp_china -0.0262 0.016 -1.651 0.099 -0.057 0.005
L8.gdp_europe 0.0751 0.025 2.970 0.003 0.026 0.125
L8.Celsius 8.826e-05 0.002 0.051 0.959 -0.003 0.003
L8.CO2_Concentration -0.0774 0.143 -0.542 0.588 -0.357 0.202
L9.oil_spot_WTI -0.0057 0.001 -4.055 0.000 -0.008 -0.003
L9.gdp_us -0.1101 0.041 -2.711 0.007 -0.190 -0.030
L9.gdp_china 0.0379 0.013 2.920 0.003 0.012 0.063
L9.gdp_europe 0.0626 0.025 2.515 0.012 0.014 0.111
L9.Celsius -0.0033 0.001 -2.421 0.015 -0.006 -0.001
L9.CO2_Concentration -0.5928 0.118 -5.044 0.000 -0.823 -0.362
L10.oil_spot_WTI 0.0002 0.001 0.127 0.899 -0.002 0.003
L10.gdp_us 0.0271 0.045 0.608 0.543 -0.060 0.114
L10.gdp_china 0.0067 0.012 0.572 0.567 -0.016 0.030
L10.gdp_europe -0.0498 0.021 -2.421 0.015 -0.090 -0.009
L10.Celsius -0.0043 0.001 -3.752 0.000 -0.007 -0.002
L10.CO2_Concentration -0.0612 0.115 -0.531 0.595 -0.287 0.165
Loading coefficients (alpha) for equation oil_spot_WTI
coef std err z P>|z| [0.025 0.975]
ec1 0.4657 0.279 1.669 0.095 -0.081 1.013
ec2 -18.0309 3.534 -5.103 0.000 -24.957 -11.105
Loading coefficients (alpha) for equation gdp_us
coef std err z P>|z| [0.025 0.975]
ec1 0.0387 0.009 4.213 0.000 0.021 0.057
ec2 -0.6547 0.116 -5.622 0.000 -0.883 -0.426
Loading coefficients (alpha) for equation gdp_china
coef std err z P>|z| [0.025 0.975]
ec1 0.1363 0.015 9.325 0.000 0.108 0.165
ec2 -1.4786 0.185 -7.990 0.000 -1.841 -1.116
Loading coefficients (alpha) for equation gdp_europe
coef std err z P>|z| [0.025 0.975]
ec1 0.0409 0.014 2.927 0.003 0.014 0.068
ec2 -0.0436 0.177 -0.246 0.805 -0.391 0.303
Loading coefficients (alpha) for equation Celsius
coef std err z P>|z| [0.025 0.975]
ec1 0.7180 0.342 2.098 0.036 0.047 1.389
ec2 4.2854 4.333 0.989 0.323 -4.208 12.779
Loading coefficients (alpha) for equation CO2_Concentration
coef std err z P>|z| [0.025 0.975]
ec1 0.0052 0.003 1.825 0.068 -0.000 0.011
ec2 0.0441 0.036 1.218 0.223 -0.027 0.115
Cointegration relations for loading-coefficients-column 1
coef std err z P>|z| [0.025 0.975]
beta.1 1.0000 0 0 0.000 1.000 1.000
beta.2 -2.599e-16 0 0 0.000 -2.6e-16 -2.6e-16
beta.3 -2.9662 0.183 -16.232 0.000 -3.324 -2.608
beta.4 -4.2680 0.015 -289.972 0.000 -4.297 -4.239
beta.5 0.3603 0.380 0.949 0.343 -0.384 1.104
beta.6 77.2103 0.031 2524.775 0.000 77.150 77.270
const -311.2500 0.229 -1361.639 0.000 -311.698 -310.802
Cointegration relations for loading-coefficients-column 2
coef std err z P>|z| [0.025 0.975]
beta.1 9.375e-18 0 0 0.000 9.38e-18 9.38e-18
beta.2 1.0000 0 0 0.000 1.000 1.000
beta.3 -0.0837 0.018 -4.546 0.000 -0.120 -0.048
beta.4 -0.6691 6.015 -0.111 0.911 -12.458 11.120
beta.5 -0.0855 0.484 -0.177 0.860 -1.035 0.864
beta.6 -1.2236 28.321 -0.043 0.966 -56.733 54.285
const 10.2030 2.281 4.473 0.000 5.732 14.674

4.) Yearly analysis

4.1 CO2 Emission --> CO2 Concentration: CO2 Emissions can predict the CO2 Concentration best up to 3 year

In [132]:
fixing_index = []
fixing_value = []
for i in range(len(co2_conc)):
    if co2_conc.iloc[i].average == -999.99:
        y = co2_conc.iloc[i].year
        a = co2_conc[(co2_conc.year == y) & (co2_conc.average != -999.99)]['average'].values.mean()
        fixing_index.append(i)
        fixing_value.append(a)
    else:
        fixing_value.append(co2_conc.iloc[i].average)
co2_conc['average'] = fixing_value
co2_conc_avg = co2_conc.groupby('year').average.mean()
In [133]:
co2_conc_summary = pd.concat([co2_conc_avg,co2_conc.groupby('year').average.std()*np.sqrt(12)],axis = 1)
co2_conc_summary.columns = ['yearly_mean','yearly_vol']

con2_con_summary = pd.DataFrame(co2_conc_summary)

co2_conc_summary['%incr_mean'] = (co2_conc_summary['yearly_mean'].shift(-1) / co2_conc_summary['yearly_mean'] -1 ).fillna(0)
co2_conc_summary['%incr_vol'] = (co2_conc_summary['yearly_vol'].shift(-1) / co2_conc_summary['yearly_vol'] -1 ).fillna(0)
In [134]:
co2_conc_summary = co2_conc_summary.join(world_co2_em).join(world_co2_em_gas).join(world_co2_em_liq).join(world_co2_em_sol)
co2_analysis = co2_conc_summary.dropna()
In [135]:
# First dif
input_df = (co2_analysis[['yearly_mean','World_Emission_general']].apply(np.log) - co2_analysis[['yearly_mean','World_Emission_general']].apply(np.log).shift(1)).dropna()
In [136]:
reg_model = sm.OLS(input_df['yearly_mean'],input_df['World_Emission_general'])
result = reg_model.fit()
print(result.summary())
                            OLS Regression Results                            
==============================================================================
Dep. Variable:            yearly_mean   R-squared:                       0.435
Model:                            OLS   Adj. R-squared:                  0.420
Method:                 Least Squares   F-statistic:                     29.98
Date:                Sun, 28 Feb 2021   Prob (F-statistic):           2.77e-06
Time:                        15:24:01   Log-Likelihood:                 167.13
No. Observations:                  40   AIC:                            -332.3
Df Residuals:                      39   BIC:                            -330.6
Df Model:                           1                                         
Covariance Type:            nonrobust                                         
==========================================================================================
                             coef    std err          t      P>|t|      [0.025      0.975]
------------------------------------------------------------------------------------------
World_Emission_general     0.1131      0.021      5.475      0.000       0.071       0.155
==============================================================================
Omnibus:                        0.530   Durbin-Watson:                   1.042
Prob(Omnibus):                  0.767   Jarque-Bera (JB):                0.108
Skew:                           0.107   Prob(JB):                        0.947
Kurtosis:                       3.136   Cond. No.                         1.00
==============================================================================

Warnings:
[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.
In [137]:
r, p = stats.pearsonr(input_df['yearly_mean'],input_df['World_Emission_general'])
print(f"Scipy computed Pearson r: {r} and p-value: {p}")

fig,ax1 = plt.subplots(figsize = (15,8))
color = 'tab:red'
ax1.plot(input_df.index, input_df['yearly_mean'], color = color)
ax1.tick_params(axis = 'y',labelcolor = color)
ax1.set_xlabel('time (year)')
ax1.set_ylabel('First difference of yearly average CO2 concentration', color = color, size = 15)


ax2 = ax1.twinx()  # instantiate a second axes that shares the same x-axis

color = color = 'tab:blue'
ax2.plot(input_df.index, input_df['World_Emission_general'], color = color)
ax2.tick_params(axis = 'y',labelcolor = color)
ax2.set_ylabel('First difference of CO2 emission', color = color, size = 15)


fig.tight_layout()  # otherwise the right y-label is slightly clipped
plt.title("First difference of CO2 concentration and Emission", size = 20)
plt.show()
#1998 check trend
Scipy computed Pearson r: 0.15459854042085527 and p-value: 0.340840828622753
In [138]:
input_df_reg = input_df.copy()

input_df_reg['positive_change'] = list(map(lambda x : 0 if x <= 0 else x,input_df['World_Emission_general'] ))
input_df_reg['negative_change'] = list(map(lambda x : 0 if x >= 0 else x,input_df['World_Emission_general'] ))


input_df_reg['lag1'] = input_df['World_Emission_general'].shift(1)
input_df_reg['lag2'] = input_df['World_Emission_general'].shift(2)
input_df_reg['lag3'] = input_df['World_Emission_general'].shift(3)

input_df_reg = input_df_reg.dropna()
In [139]:
#x = input_df_reg[['positive_change','negative_change','lag1','lag2']] #,'lag3']]
#x = input_df_reg[['World_Emission_general','positive_change','negative_change','lag1','lag2','lag3']] 
x = input_df_reg[['World_Emission_general','lag1','lag2','lag3']] 
reg_model = sm.OLS(input_df_reg['yearly_mean'],x)
result = reg_model.fit()
print(result.summary())
## Three years of emissions
                            OLS Regression Results                            
==============================================================================
Dep. Variable:            yearly_mean   R-squared:                       0.738
Model:                            OLS   Adj. R-squared:                  0.707
Method:                 Least Squares   F-statistic:                     23.28
Date:                Sun, 28 Feb 2021   Prob (F-statistic):           3.26e-09
Time:                        15:24:02   Log-Likelihood:                 168.63
No. Observations:                  37   AIC:                            -329.3
Df Residuals:                      33   BIC:                            -322.8
Df Model:                           4                                         
Covariance Type:            nonrobust                                         
==========================================================================================
                             coef    std err          t      P>|t|      [0.025      0.975]
------------------------------------------------------------------------------------------
World_Emission_general     0.0535      0.020      2.735      0.010       0.014       0.093
lag1                       0.0417      0.020      2.054      0.048       0.000       0.083
lag2                       0.0450      0.019      2.340      0.026       0.006       0.084
lag3                       0.0474      0.018      2.610      0.014       0.010       0.084
==============================================================================
Omnibus:                        3.104   Durbin-Watson:                   0.817
Prob(Omnibus):                  0.212   Jarque-Bera (JB):                1.902
Skew:                           0.484   Prob(JB):                        0.386
Kurtosis:                       3.543   Cond. No.                         2.37
==============================================================================

Warnings:
[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.
In [140]:
# test perfect number of lags used in model with positive/negative change in emissions
nlag = 10

for i in range(nlag+1):
    #print(i)
    input_df_reg_loop = input_df.copy()
    input_df_reg_loop['positive_change'] = list(map(lambda x : 0 if x <= 0 else x,input_df['World_Emission_general'] ))
    input_df_reg_loop['negative_change'] = list(map(lambda x : 0 if x >= 0 else x,input_df['World_Emission_general'] ))
    #running = i.copy()
    column_names = ['positive_change','negative_change']
    print("Number of lag : ", str(i))
    while i > 0:
        text = 'lag' + '_' + str(i)
        input_df_reg_loop[text] = input_df['World_Emission_general'].shift(i)
        column_names.append(text)
        i = i - 1

    input_df_reg_loop = input_df_reg_loop.dropna()
    
    x = input_df_reg_loop[column_names]
    reg_model = sm.OLS(input_df_reg_loop['yearly_mean'],x)
    result = reg_model.fit()
    print("R-squared : ", result.rsquared)
    print("P-value : ")
    print(result.pvalues)
    print(" ")
Number of lag :  0
R-squared :  0.6676249832624084
P-value : 
positive_change    7.910400e-10
negative_change    2.614309e-03
dtype: float64
 
Number of lag :  1
R-squared :  0.7489629532325237
P-value : 
positive_change    0.000001
negative_change    0.006127
lag_1              0.002529
dtype: float64
 
Number of lag :  2
R-squared :  0.7806960060472822
P-value : 
positive_change    0.000033
negative_change    0.019940
lag_2              0.074281
lag_1              0.020307
dtype: float64
 
Number of lag :  3
R-squared :  0.7961449630560566
P-value : 
positive_change    0.000205
negative_change    0.060420
lag_3              0.070357
lag_2              0.138196
lag_1              0.061134
dtype: float64
 
Number of lag :  4
R-squared :  0.814253624521907
P-value : 
positive_change    0.000209
negative_change    0.200912
lag_4              0.074723
lag_3              0.122517
lag_2              0.351593
lag_1              0.112364
dtype: float64
 
Number of lag :  5
R-squared :  0.8229562861014313
P-value : 
positive_change    0.000838
negative_change    0.340920
lag_5              0.574947
lag_4              0.162853
lag_3              0.093787
lag_2              0.356402
lag_1              0.154278
dtype: float64
 
Number of lag :  6
R-squared :  0.8374479688765397
P-value : 
positive_change    0.002516
negative_change    0.484335
lag_6              0.086141
lag_5              0.894828
lag_4              0.458700
lag_3              0.145635
lag_2              0.157037
lag_1              0.246940
dtype: float64
 
Number of lag :  7
R-squared :  0.8515831127290536
P-value : 
positive_change    0.014934
negative_change    0.870616
lag_7              0.117498
lag_6              0.322997
lag_5              0.976700
lag_4              0.543808
lag_3              0.066174
lag_2              0.201578
lag_1              0.248734
dtype: float64
 
Number of lag :  8
R-squared :  0.8563173821506386
P-value : 
positive_change    0.035568
negative_change    0.935050
lag_8              0.443271
lag_7              0.206206
lag_6              0.567301
lag_5              0.976347
lag_4              0.396834
lag_3              0.146426
lag_2              0.192935
lag_1              0.276467
dtype: float64
 
Number of lag :  9
R-squared :  0.8932211842892088
P-value : 
positive_change    0.034440
negative_change    0.961644
lag_9              0.128790
lag_8              0.514766
lag_7              0.685534
lag_6              0.728259
lag_5              0.456229
lag_4              0.886511
lag_3              0.073093
lag_2              0.102312
lag_1              0.447118
dtype: float64
 
Number of lag :  10
R-squared :  0.9118846140255947
P-value : 
positive_change    0.050274
negative_change    0.960156
lag_10             0.124013
lag_9              0.249157
lag_8              0.848590
lag_7              0.956695
lag_6              0.303618
lag_5              0.690871
lag_4              0.809725
lag_3              0.089014
lag_2              0.168612
lag_1              0.476138
dtype: float64
 

Decided to use only up to 3 lags - highest r square and significant variables

4.2 Oil price to CO2 Concentration: Yearly change oil price with 1 lag is a best predictor to yearly change CO2 concentration

In [141]:
oil_co2_df
Out[141]:
Weekindex Date Year Month Week Day Par_Month Par_Day oil_spot_WTI oil_spot_Brent ... Date_edited year month day decimal average ndays 1_year_ago 10_years_ago increase_since_1800
Par_Week
19910205 266 2/1/1991 1991 2 5 1 199102 19910901 21.33 20.80 ... 1991-02-01 1991.0 2.0 3.0 1991.0918 355.23 7.0 354.95 340.03 74.73
19910206 267 2/8/1991 1991 2 6 8 199102 19910908 21.78 20.65 ... 1991-02-08 1991.0 2.0 10.0 1991.1110 355.79 6.0 355.09 340.74 75.12
19910207 268 2/15/1991 1991 2 7 15 199102 19910915 20.73 18.35 ... 1991-02-15 1991.0 2.0 17.0 1991.1301 356.44 6.0 355.30 340.20 75.61
19910208 269 2/22/1991 1991 2 8 22 199102 19910922 17.43 17.80 ... 1991-02-22 1991.0 2.0 24.0 1991.1493 355.73 7.0 355.02 341.52 74.72
19910309 270 3/1/1991 1991 3 9 1 199103 19910901 19.43 19.33 ... 1991-03-01 1991.0 3.0 3.0 1991.1685 357.08 6.0 355.76 341.15 75.87
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
20201253 1827 12/31/2020 2020 12 53 31 202012 20201231 48.35 51.22 ... 2020-12-31 2021.0 1.0 3.0 2021.0068 415.25 7.0 413.39 391.73 135.20
20210102 1828 1/8/2021 2021 1 2 8 202101 20210108 52.14 55.51 ... 2021-01-08 NaN NaN NaN NaN NaN NaN NaN NaN NaN
20210103 1829 1/15/2021 2021 1 3 15 202101 20210115 52.25 54.80 ... 2021-01-15 NaN NaN NaN NaN NaN NaN NaN NaN NaN
20210104 1830 1/22/2021 2021 1 4 22 202101 20210122 52.28 55.22 ... 2021-01-22 NaN NaN NaN NaN NaN NaN NaN NaN NaN
20210105 1831 1/25/2021 2021 1 5 25 202101 20210125 52.78 55.44 ... 2021-01-25 NaN NaN NaN NaN NaN NaN NaN NaN NaN

1566 rows × 34 columns

In [142]:
# Choosing last Month data
year_oil_co2_df = oil_co2_df.groupby('Year').last().copy()

#Joining data to create big dataframe - yearly data

y_glob_temp = glob_temp.copy()
index = y_glob_temp.index
year_index = []
for i in index:
    year_index.append(str(i)[:4])
y_glob_temp['Year'] = [int(i) for i in year_index] 
y_glob_temp = y_glob_temp.set_index('Year')
y_glob_temp = y_glob_temp.groupby('Year').last()


y_gdp = gdp_df.copy()
index = y_gdp.index
year_index = []
for i in index:
    year_index.append(str(i)[:4])
y_gdp['Year'] = [int(i) for i in year_index] 
y_gdp = y_gdp.set_index('Year')
y_gdp = y_gdp.groupby('Year').last()


y_analysis_df = year_oil_co2_df.join(y_gdp.drop(columns = ['Month'])).dropna(subset=['gdp_date','gdp_us','gdp_china','gdp_europe'])
y_analysis_df = y_analysis_df.join(y_glob_temp['Celsius'])

#Rename Carbon Dioxide concentration 

temp = y_analysis_df['average']
y_analysis_df = y_analysis_df.drop(columns = 'average')
y_analysis_df['CO2_Concentration'] = temp

y_analysis_df = y_analysis_df.drop(columns = 'gdp_date')
y_analysis_df.head()

#Create first difference

temp_frame = (np.log(y_analysis_df[['gdp_china','gdp_us','gdp_europe','Celsius','CO2_Concentration']].shift(0)) - np.log(y_analysis_df[['gdp_china','gdp_us','gdp_europe','Celsius','CO2_Concentration']].shift(1)))
temp_frame = temp_frame.rename(columns = {'gdp_china' : 'chg_gdp_china','gdp_europe':'chg_gdp_europe','gdp_us':'chg_gdp_us','Celsius':'chg_celsius','CO2_Concentration':'chg_co2_concentration'})
y_analysis_df =  y_analysis_df.merge(temp_frame, how='inner', on='Year')
                                     
y_analysis_df.head()
y_analysis_df = y_analysis_df.iloc[1:]

#Export data to output table
y_analysis_df.to_csv('yearly_analysis_prep_data.csv')
In [143]:
quick_anaysis = y_analysis_df.copy()


# test perfect number of lags used in model
import statsmodels.api as sm

nlag = 20

for i in range(nlag+1):
    #print(i)
    quick_anaysis_df_loop = quick_anaysis.copy()
    #running = i.copy()
    column_names = ['chg_oil_spot_WTI_Positive','chg_oil_spot_WTI_Negative','chg_gdp_us','chg_gdp_china','chg_gdp_europe']
    print("Number of lag : ", str(i))
    while i > 0:
        text = 'lag' + '_' + str(i)
        
        quick_anaysis_df_loop[text] = quick_anaysis['oil_spot_WTI'].shift(i)
        
        quick_anaysis_df_loop['chg_oil_spot_WTI' + "_" + text] = quick_anaysis['oil_spot_WTI'].shift(i)
        
        quick_anaysis_df_loop['chg_gdp_us' + "_" + text] = quick_anaysis['gdp_us'].shift(i)
        
        quick_anaysis_df_loop['chg_gdp_china' + "_" + text] = quick_anaysis['gdp_china'].shift(i)
        
        quick_anaysis_df_loop['chg_gdp_europe' + "_" + text] = quick_anaysis['gdp_europe'].shift(i)

        column_names.append('chg_oil_spot_WTI' + "_" + text)
        column_names.append('chg_gdp_us' + "_" + text)
        column_names.append('chg_gdp_china' + "_" + text)
        column_names.append('chg_gdp_europe' + "_" + text)

        i = i - 1
        #print(i+1)
    #print(" ")
    quick_anaysis_df_loop = quick_anaysis_df_loop.dropna()
    
    x = quick_anaysis_df_loop[column_names] 
    reg_model = sm.OLS(quick_anaysis_df_loop['chg_co2_concentration'],x)
    result = reg_model.fit()
    print("R-squared : ", result.rsquared)
    print("P-value : ")
    print(round(result.pvalues,4))
    print(" ")
Number of lag :  0
R-squared :  0.9267375084458885
P-value : 
chg_oil_spot_WTI_Positive    0.3341
chg_oil_spot_WTI_Negative    0.5315
chg_gdp_us                   0.0099
chg_gdp_china                0.4395
chg_gdp_europe               0.1678
dtype: float64
 
Number of lag :  1
R-squared :  0.42923125612237156
P-value : 
chg_oil_spot_WTI_Positive    0.6134
chg_oil_spot_WTI_Negative    0.8019
chg_gdp_us                   0.2011
chg_gdp_china                0.3730
chg_gdp_europe               0.2631
chg_oil_spot_WTI_lag_1       0.8498
chg_gdp_us_lag_1             0.5289
chg_gdp_china_lag_1          0.4283
chg_gdp_europe_lag_1         0.4607
dtype: float64
 
Number of lag :  2
R-squared :  0.7059594909452043
P-value : 
chg_oil_spot_WTI_Positive    0.0392
chg_oil_spot_WTI_Negative    0.0392
chg_gdp_us                   0.0392
chg_gdp_china                0.0392
chg_gdp_europe               0.0392
chg_oil_spot_WTI_lag_2       0.1931
chg_gdp_us_lag_2             0.0711
chg_gdp_china_lag_2          0.2371
chg_gdp_europe_lag_2         0.0952
chg_oil_spot_WTI_lag_1       0.3801
chg_gdp_us_lag_1             0.4195
chg_gdp_china_lag_1          0.9796
chg_gdp_europe_lag_1         0.0963
dtype: float64
 
Number of lag :  3
R-squared :  0.5703941279151961
P-value : 
chg_oil_spot_WTI_Positive    0.6138
chg_oil_spot_WTI_Negative    0.5811
chg_gdp_us                   0.6556
chg_gdp_china                0.6136
chg_gdp_europe               0.5571
chg_oil_spot_WTI_lag_3       0.7992
chg_gdp_us_lag_3             0.4538
chg_gdp_china_lag_3          0.5707
chg_gdp_europe_lag_3         0.6466
chg_oil_spot_WTI_lag_2       0.6624
chg_gdp_us_lag_2             0.3774
chg_gdp_china_lag_2          0.6071
chg_gdp_europe_lag_2         0.4531
chg_oil_spot_WTI_lag_1       0.5512
chg_gdp_us_lag_1             0.4480
chg_gdp_china_lag_1          0.8083
chg_gdp_europe_lag_1         0.6025
dtype: float64
 
Number of lag :  4
R-squared :  0.999999999999773
P-value : 
chg_oil_spot_WTI_Positive   NaN
chg_oil_spot_WTI_Negative   NaN
chg_gdp_us                  NaN
chg_gdp_china               NaN
chg_gdp_europe              NaN
chg_oil_spot_WTI_lag_4      NaN
chg_gdp_us_lag_4            NaN
chg_gdp_china_lag_4         NaN
chg_gdp_europe_lag_4        NaN
chg_oil_spot_WTI_lag_3      NaN
chg_gdp_us_lag_3            NaN
chg_gdp_china_lag_3         NaN
chg_gdp_europe_lag_3        NaN
chg_oil_spot_WTI_lag_2      NaN
chg_gdp_us_lag_2            NaN
chg_gdp_china_lag_2         NaN
chg_gdp_europe_lag_2        NaN
chg_oil_spot_WTI_lag_1      NaN
chg_gdp_us_lag_1            NaN
chg_gdp_china_lag_1         NaN
chg_gdp_europe_lag_1        NaN
dtype: float64
 
Number of lag :  5
C:\Users\DELL\Anaconda3\lib\site-packages\statsmodels\regression\linear_model.py:1510: RuntimeWarning: divide by zero encountered in double_scalars
  return np.dot(wresid, wresid) / self.df_resid
C:\Users\DELL\Anaconda3\lib\site-packages\statsmodels\regression\linear_model.py:1510: RuntimeWarning: divide by zero encountered in double_scalars
  return np.dot(wresid, wresid) / self.df_resid
C:\Users\DELL\Anaconda3\lib\site-packages\statsmodels\regression\linear_model.py:1510: RuntimeWarning: divide by zero encountered in double_scalars
  return np.dot(wresid, wresid) / self.df_resid
R-squared :  0.9999999999999057
P-value : 
chg_oil_spot_WTI_Positive   NaN
chg_oil_spot_WTI_Negative   NaN
chg_gdp_us                  NaN
chg_gdp_china               NaN
chg_gdp_europe              NaN
chg_oil_spot_WTI_lag_5      NaN
chg_gdp_us_lag_5            NaN
chg_gdp_china_lag_5         NaN
chg_gdp_europe_lag_5        NaN
chg_oil_spot_WTI_lag_4      NaN
chg_gdp_us_lag_4            NaN
chg_gdp_china_lag_4         NaN
chg_gdp_europe_lag_4        NaN
chg_oil_spot_WTI_lag_3      NaN
chg_gdp_us_lag_3            NaN
chg_gdp_china_lag_3         NaN
chg_gdp_europe_lag_3        NaN
chg_oil_spot_WTI_lag_2      NaN
chg_gdp_us_lag_2            NaN
chg_gdp_china_lag_2         NaN
chg_gdp_europe_lag_2        NaN
chg_oil_spot_WTI_lag_1      NaN
chg_gdp_us_lag_1            NaN
chg_gdp_china_lag_1         NaN
chg_gdp_europe_lag_1        NaN
dtype: float64
 
Number of lag :  6
R-squared :  0.9999999999999937
P-value : 
chg_oil_spot_WTI_Positive   NaN
chg_oil_spot_WTI_Negative   NaN
chg_gdp_us                  NaN
chg_gdp_china               NaN
chg_gdp_europe              NaN
chg_oil_spot_WTI_lag_6      NaN
chg_gdp_us_lag_6            NaN
chg_gdp_china_lag_6         NaN
chg_gdp_europe_lag_6        NaN
chg_oil_spot_WTI_lag_5      NaN
chg_gdp_us_lag_5            NaN
chg_gdp_china_lag_5         NaN
chg_gdp_europe_lag_5        NaN
chg_oil_spot_WTI_lag_4      NaN
chg_gdp_us_lag_4            NaN
chg_gdp_china_lag_4         NaN
chg_gdp_europe_lag_4        NaN
chg_oil_spot_WTI_lag_3      NaN
chg_gdp_us_lag_3            NaN
chg_gdp_china_lag_3         NaN
chg_gdp_europe_lag_3        NaN
chg_oil_spot_WTI_lag_2      NaN
chg_gdp_us_lag_2            NaN
chg_gdp_china_lag_2         NaN
chg_gdp_europe_lag_2        NaN
chg_oil_spot_WTI_lag_1      NaN
chg_gdp_us_lag_1            NaN
chg_gdp_china_lag_1         NaN
chg_gdp_europe_lag_1        NaN
dtype: float64
 
Number of lag :  7
R-squared :  0.9999999999999998
P-value : 
chg_oil_spot_WTI_Positive   NaN
chg_oil_spot_WTI_Negative   NaN
chg_gdp_us                  NaN
chg_gdp_china               NaN
chg_gdp_europe              NaN
chg_oil_spot_WTI_lag_7      NaN
chg_gdp_us_lag_7            NaN
chg_gdp_china_lag_7         NaN
chg_gdp_europe_lag_7        NaN
chg_oil_spot_WTI_lag_6      NaN
chg_gdp_us_lag_6            NaN
chg_gdp_china_lag_6         NaN
chg_gdp_europe_lag_6        NaN
chg_oil_spot_WTI_lag_5      NaN
chg_gdp_us_lag_5            NaN
chg_gdp_china_lag_5         NaN
chg_gdp_europe_lag_5        NaN
chg_oil_spot_WTI_lag_4      NaN
chg_gdp_us_lag_4            NaN
chg_gdp_china_lag_4         NaN
chg_gdp_europe_lag_4        NaN
chg_oil_spot_WTI_lag_3      NaN
chg_gdp_us_lag_3            NaN
chg_gdp_china_lag_3         NaN
chg_gdp_europe_lag_3        NaN
chg_oil_spot_WTI_lag_2      NaN
chg_gdp_us_lag_2            NaN
chg_gdp_china_lag_2         NaN
chg_gdp_europe_lag_2        NaN
chg_oil_spot_WTI_lag_1      NaN
chg_gdp_us_lag_1            NaN
chg_gdp_china_lag_1         NaN
chg_gdp_europe_lag_1        NaN
dtype: float64
 
Number of lag :  8
R-squared :  1.0
P-value : 
chg_oil_spot_WTI_Positive   NaN
chg_oil_spot_WTI_Negative   NaN
chg_gdp_us                  NaN
chg_gdp_china               NaN
chg_gdp_europe              NaN
chg_oil_spot_WTI_lag_8      NaN
chg_gdp_us_lag_8            NaN
chg_gdp_china_lag_8         NaN
chg_gdp_europe_lag_8        NaN
chg_oil_spot_WTI_lag_7      NaN
chg_gdp_us_lag_7            NaN
chg_gdp_china_lag_7         NaN
chg_gdp_europe_lag_7        NaN
chg_oil_spot_WTI_lag_6      NaN
chg_gdp_us_lag_6            NaN
chg_gdp_china_lag_6         NaN
chg_gdp_europe_lag_6        NaN
chg_oil_spot_WTI_lag_5      NaN
chg_gdp_us_lag_5            NaN
chg_gdp_china_lag_5         NaN
chg_gdp_europe_lag_5        NaN
chg_oil_spot_WTI_lag_4      NaN
chg_gdp_us_lag_4            NaN
chg_gdp_china_lag_4         NaN
chg_gdp_europe_lag_4        NaN
chg_oil_spot_WTI_lag_3      NaN
chg_gdp_us_lag_3            NaN
chg_gdp_china_lag_3         NaN
chg_gdp_europe_lag_3        NaN
chg_oil_spot_WTI_lag_2      NaN
chg_gdp_us_lag_2            NaN
chg_gdp_china_lag_2         NaN
chg_gdp_europe_lag_2        NaN
chg_oil_spot_WTI_lag_1      NaN
chg_gdp_us_lag_1            NaN
chg_gdp_china_lag_1         NaN
chg_gdp_europe_lag_1        NaN
dtype: float64
 
Number of lag :  9
C:\Users\DELL\Anaconda3\lib\site-packages\statsmodels\regression\linear_model.py:1510: RuntimeWarning: divide by zero encountered in double_scalars
  return np.dot(wresid, wresid) / self.df_resid
C:\Users\DELL\Anaconda3\lib\site-packages\statsmodels\regression\linear_model.py:1510: RuntimeWarning: divide by zero encountered in double_scalars
  return np.dot(wresid, wresid) / self.df_resid
C:\Users\DELL\Anaconda3\lib\site-packages\statsmodels\regression\linear_model.py:1510: RuntimeWarning: divide by zero encountered in double_scalars
  return np.dot(wresid, wresid) / self.df_resid
C:\Users\DELL\Anaconda3\lib\site-packages\statsmodels\regression\linear_model.py:1510: RuntimeWarning: divide by zero encountered in double_scalars
  return np.dot(wresid, wresid) / self.df_resid
R-squared :  1.0
P-value : 
chg_oil_spot_WTI_Positive   NaN
chg_oil_spot_WTI_Negative   NaN
chg_gdp_us                  NaN
chg_gdp_china               NaN
chg_gdp_europe              NaN
chg_oil_spot_WTI_lag_9      NaN
chg_gdp_us_lag_9            NaN
chg_gdp_china_lag_9         NaN
chg_gdp_europe_lag_9        NaN
chg_oil_spot_WTI_lag_8      NaN
chg_gdp_us_lag_8            NaN
chg_gdp_china_lag_8         NaN
chg_gdp_europe_lag_8        NaN
chg_oil_spot_WTI_lag_7      NaN
chg_gdp_us_lag_7            NaN
chg_gdp_china_lag_7         NaN
chg_gdp_europe_lag_7        NaN
chg_oil_spot_WTI_lag_6      NaN
chg_gdp_us_lag_6            NaN
chg_gdp_china_lag_6         NaN
chg_gdp_europe_lag_6        NaN
chg_oil_spot_WTI_lag_5      NaN
chg_gdp_us_lag_5            NaN
chg_gdp_china_lag_5         NaN
chg_gdp_europe_lag_5        NaN
chg_oil_spot_WTI_lag_4      NaN
chg_gdp_us_lag_4            NaN
chg_gdp_china_lag_4         NaN
chg_gdp_europe_lag_4        NaN
chg_oil_spot_WTI_lag_3      NaN
chg_gdp_us_lag_3            NaN
chg_gdp_china_lag_3         NaN
chg_gdp_europe_lag_3        NaN
chg_oil_spot_WTI_lag_2      NaN
chg_gdp_us_lag_2            NaN
chg_gdp_china_lag_2         NaN
chg_gdp_europe_lag_2        NaN
chg_oil_spot_WTI_lag_1      NaN
chg_gdp_us_lag_1            NaN
chg_gdp_china_lag_1         NaN
chg_gdp_europe_lag_1        NaN
dtype: float64
 
Number of lag :  10
R-squared :  1.0
P-value : 
chg_oil_spot_WTI_Positive   NaN
chg_oil_spot_WTI_Negative   NaN
chg_gdp_us                  NaN
chg_gdp_china               NaN
chg_gdp_europe              NaN
chg_oil_spot_WTI_lag_10     NaN
chg_gdp_us_lag_10           NaN
chg_gdp_china_lag_10        NaN
chg_gdp_europe_lag_10       NaN
chg_oil_spot_WTI_lag_9      NaN
chg_gdp_us_lag_9            NaN
chg_gdp_china_lag_9         NaN
chg_gdp_europe_lag_9        NaN
chg_oil_spot_WTI_lag_8      NaN
chg_gdp_us_lag_8            NaN
chg_gdp_china_lag_8         NaN
chg_gdp_europe_lag_8        NaN
chg_oil_spot_WTI_lag_7      NaN
chg_gdp_us_lag_7            NaN
chg_gdp_china_lag_7         NaN
chg_gdp_europe_lag_7        NaN
chg_oil_spot_WTI_lag_6      NaN
chg_gdp_us_lag_6            NaN
chg_gdp_china_lag_6         NaN
chg_gdp_europe_lag_6        NaN
chg_oil_spot_WTI_lag_5      NaN
chg_gdp_us_lag_5            NaN
chg_gdp_china_lag_5         NaN
chg_gdp_europe_lag_5        NaN
chg_oil_spot_WTI_lag_4      NaN
chg_gdp_us_lag_4            NaN
chg_gdp_china_lag_4         NaN
chg_gdp_europe_lag_4        NaN
chg_oil_spot_WTI_lag_3      NaN
chg_gdp_us_lag_3            NaN
chg_gdp_china_lag_3         NaN
chg_gdp_europe_lag_3        NaN
chg_oil_spot_WTI_lag_2      NaN
chg_gdp_us_lag_2            NaN
chg_gdp_china_lag_2         NaN
chg_gdp_europe_lag_2        NaN
chg_oil_spot_WTI_lag_1      NaN
chg_gdp_us_lag_1            NaN
chg_gdp_china_lag_1         NaN
chg_gdp_europe_lag_1        NaN
dtype: float64
 
Number of lag :  11
R-squared :  1.0
P-value : 
chg_oil_spot_WTI_Positive   NaN
chg_oil_spot_WTI_Negative   NaN
chg_gdp_us                  NaN
chg_gdp_china               NaN
chg_gdp_europe              NaN
chg_oil_spot_WTI_lag_11     NaN
chg_gdp_us_lag_11           NaN
chg_gdp_china_lag_11        NaN
chg_gdp_europe_lag_11       NaN
chg_oil_spot_WTI_lag_10     NaN
chg_gdp_us_lag_10           NaN
chg_gdp_china_lag_10        NaN
chg_gdp_europe_lag_10       NaN
chg_oil_spot_WTI_lag_9      NaN
chg_gdp_us_lag_9            NaN
chg_gdp_china_lag_9         NaN
chg_gdp_europe_lag_9        NaN
chg_oil_spot_WTI_lag_8      NaN
chg_gdp_us_lag_8            NaN
chg_gdp_china_lag_8         NaN
chg_gdp_europe_lag_8        NaN
chg_oil_spot_WTI_lag_7      NaN
chg_gdp_us_lag_7            NaN
chg_gdp_china_lag_7         NaN
chg_gdp_europe_lag_7        NaN
chg_oil_spot_WTI_lag_6      NaN
chg_gdp_us_lag_6            NaN
chg_gdp_china_lag_6         NaN
chg_gdp_europe_lag_6        NaN
chg_oil_spot_WTI_lag_5      NaN
chg_gdp_us_lag_5            NaN
chg_gdp_china_lag_5         NaN
chg_gdp_europe_lag_5        NaN
chg_oil_spot_WTI_lag_4      NaN
chg_gdp_us_lag_4            NaN
chg_gdp_china_lag_4         NaN
chg_gdp_europe_lag_4        NaN
chg_oil_spot_WTI_lag_3      NaN
chg_gdp_us_lag_3            NaN
chg_gdp_china_lag_3         NaN
chg_gdp_europe_lag_3        NaN
chg_oil_spot_WTI_lag_2      NaN
chg_gdp_us_lag_2            NaN
chg_gdp_china_lag_2         NaN
chg_gdp_europe_lag_2        NaN
chg_oil_spot_WTI_lag_1      NaN
chg_gdp_us_lag_1            NaN
chg_gdp_china_lag_1         NaN
chg_gdp_europe_lag_1        NaN
dtype: float64
 
Number of lag :  12
C:\Users\DELL\Anaconda3\lib\site-packages\statsmodels\regression\linear_model.py:1510: RuntimeWarning: divide by zero encountered in double_scalars
  return np.dot(wresid, wresid) / self.df_resid
C:\Users\DELL\Anaconda3\lib\site-packages\statsmodels\regression\linear_model.py:1510: RuntimeWarning: divide by zero encountered in double_scalars
  return np.dot(wresid, wresid) / self.df_resid
R-squared :  1.0
P-value : 
chg_oil_spot_WTI_Positive   NaN
chg_oil_spot_WTI_Negative   NaN
chg_gdp_us                  NaN
chg_gdp_china               NaN
chg_gdp_europe              NaN
chg_oil_spot_WTI_lag_12     NaN
chg_gdp_us_lag_12           NaN
chg_gdp_china_lag_12        NaN
chg_gdp_europe_lag_12       NaN
chg_oil_spot_WTI_lag_11     NaN
chg_gdp_us_lag_11           NaN
chg_gdp_china_lag_11        NaN
chg_gdp_europe_lag_11       NaN
chg_oil_spot_WTI_lag_10     NaN
chg_gdp_us_lag_10           NaN
chg_gdp_china_lag_10        NaN
chg_gdp_europe_lag_10       NaN
chg_oil_spot_WTI_lag_9      NaN
chg_gdp_us_lag_9            NaN
chg_gdp_china_lag_9         NaN
chg_gdp_europe_lag_9        NaN
chg_oil_spot_WTI_lag_8      NaN
chg_gdp_us_lag_8            NaN
chg_gdp_china_lag_8         NaN
chg_gdp_europe_lag_8        NaN
chg_oil_spot_WTI_lag_7      NaN
chg_gdp_us_lag_7            NaN
chg_gdp_china_lag_7         NaN
chg_gdp_europe_lag_7        NaN
chg_oil_spot_WTI_lag_6      NaN
chg_gdp_us_lag_6            NaN
chg_gdp_china_lag_6         NaN
chg_gdp_europe_lag_6        NaN
chg_oil_spot_WTI_lag_5      NaN
chg_gdp_us_lag_5            NaN
chg_gdp_china_lag_5         NaN
chg_gdp_europe_lag_5        NaN
chg_oil_spot_WTI_lag_4      NaN
chg_gdp_us_lag_4            NaN
chg_gdp_china_lag_4         NaN
chg_gdp_europe_lag_4        NaN
chg_oil_spot_WTI_lag_3      NaN
chg_gdp_us_lag_3            NaN
chg_gdp_china_lag_3         NaN
chg_gdp_europe_lag_3        NaN
chg_oil_spot_WTI_lag_2      NaN
chg_gdp_us_lag_2            NaN
chg_gdp_china_lag_2         NaN
chg_gdp_europe_lag_2        NaN
chg_oil_spot_WTI_lag_1      NaN
chg_gdp_us_lag_1            NaN
chg_gdp_china_lag_1         NaN
chg_gdp_europe_lag_1        NaN
dtype: float64
 
Number of lag :  13
R-squared :  1.0
P-value : 
chg_oil_spot_WTI_Positive   NaN
chg_oil_spot_WTI_Negative   NaN
chg_gdp_us                  NaN
chg_gdp_china               NaN
chg_gdp_europe              NaN
chg_oil_spot_WTI_lag_13     NaN
chg_gdp_us_lag_13           NaN
chg_gdp_china_lag_13        NaN
chg_gdp_europe_lag_13       NaN
chg_oil_spot_WTI_lag_12     NaN
chg_gdp_us_lag_12           NaN
chg_gdp_china_lag_12        NaN
chg_gdp_europe_lag_12       NaN
chg_oil_spot_WTI_lag_11     NaN
chg_gdp_us_lag_11           NaN
chg_gdp_china_lag_11        NaN
chg_gdp_europe_lag_11       NaN
chg_oil_spot_WTI_lag_10     NaN
chg_gdp_us_lag_10           NaN
chg_gdp_china_lag_10        NaN
chg_gdp_europe_lag_10       NaN
chg_oil_spot_WTI_lag_9      NaN
chg_gdp_us_lag_9            NaN
chg_gdp_china_lag_9         NaN
chg_gdp_europe_lag_9        NaN
chg_oil_spot_WTI_lag_8      NaN
chg_gdp_us_lag_8            NaN
chg_gdp_china_lag_8         NaN
chg_gdp_europe_lag_8        NaN
chg_oil_spot_WTI_lag_7      NaN
chg_gdp_us_lag_7            NaN
chg_gdp_china_lag_7         NaN
chg_gdp_europe_lag_7        NaN
chg_oil_spot_WTI_lag_6      NaN
chg_gdp_us_lag_6            NaN
chg_gdp_china_lag_6         NaN
chg_gdp_europe_lag_6        NaN
chg_oil_spot_WTI_lag_5      NaN
chg_gdp_us_lag_5            NaN
chg_gdp_china_lag_5         NaN
chg_gdp_europe_lag_5        NaN
chg_oil_spot_WTI_lag_4      NaN
chg_gdp_us_lag_4            NaN
chg_gdp_china_lag_4         NaN
chg_gdp_europe_lag_4        NaN
chg_oil_spot_WTI_lag_3      NaN
chg_gdp_us_lag_3            NaN
chg_gdp_china_lag_3         NaN
chg_gdp_europe_lag_3        NaN
chg_oil_spot_WTI_lag_2      NaN
chg_gdp_us_lag_2            NaN
chg_gdp_china_lag_2         NaN
chg_gdp_europe_lag_2        NaN
chg_oil_spot_WTI_lag_1      NaN
chg_gdp_us_lag_1            NaN
chg_gdp_china_lag_1         NaN
chg_gdp_europe_lag_1        NaN
dtype: float64
 
Number of lag :  14
C:\Users\DELL\Anaconda3\lib\site-packages\statsmodels\regression\linear_model.py:1510: RuntimeWarning: divide by zero encountered in double_scalars
  return np.dot(wresid, wresid) / self.df_resid
C:\Users\DELL\Anaconda3\lib\site-packages\statsmodels\regression\linear_model.py:1510: RuntimeWarning: divide by zero encountered in double_scalars
  return np.dot(wresid, wresid) / self.df_resid
R-squared :  1.0
P-value : 
chg_oil_spot_WTI_Positive   NaN
chg_oil_spot_WTI_Negative   NaN
chg_gdp_us                  NaN
chg_gdp_china               NaN
chg_gdp_europe              NaN
                             ..
chg_gdp_europe_lag_2        NaN
chg_oil_spot_WTI_lag_1      NaN
chg_gdp_us_lag_1            NaN
chg_gdp_china_lag_1         NaN
chg_gdp_europe_lag_1        NaN
Length: 61, dtype: float64
 
Number of lag :  15
R-squared :  1.0
P-value : 
chg_oil_spot_WTI_Positive   NaN
chg_oil_spot_WTI_Negative   NaN
chg_gdp_us                  NaN
chg_gdp_china               NaN
chg_gdp_europe              NaN
                             ..
chg_gdp_europe_lag_2        NaN
chg_oil_spot_WTI_lag_1      NaN
chg_gdp_us_lag_1            NaN
chg_gdp_china_lag_1         NaN
chg_gdp_europe_lag_1        NaN
Length: 65, dtype: float64
 
Number of lag :  16
C:\Users\DELL\Anaconda3\lib\site-packages\statsmodels\regression\linear_model.py:1510: RuntimeWarning: divide by zero encountered in double_scalars
  return np.dot(wresid, wresid) / self.df_resid
C:\Users\DELL\Anaconda3\lib\site-packages\statsmodels\regression\linear_model.py:1510: RuntimeWarning: divide by zero encountered in double_scalars
  return np.dot(wresid, wresid) / self.df_resid
C:\Users\DELL\Anaconda3\lib\site-packages\statsmodels\regression\linear_model.py:1510: RuntimeWarning: divide by zero encountered in double_scalars
  return np.dot(wresid, wresid) / self.df_resid
R-squared :  1.0
P-value : 
chg_oil_spot_WTI_Positive   NaN
chg_oil_spot_WTI_Negative   NaN
chg_gdp_us                  NaN
chg_gdp_china               NaN
chg_gdp_europe              NaN
                             ..
chg_gdp_europe_lag_2        NaN
chg_oil_spot_WTI_lag_1      NaN
chg_gdp_us_lag_1            NaN
chg_gdp_china_lag_1         NaN
chg_gdp_europe_lag_1        NaN
Length: 69, dtype: float64
 
Number of lag :  17
R-squared :  1.0
P-value : 
chg_oil_spot_WTI_Positive   NaN
chg_oil_spot_WTI_Negative   NaN
chg_gdp_us                  NaN
chg_gdp_china               NaN
chg_gdp_europe              NaN
                             ..
chg_gdp_europe_lag_2        NaN
chg_oil_spot_WTI_lag_1      NaN
chg_gdp_us_lag_1            NaN
chg_gdp_china_lag_1         NaN
chg_gdp_europe_lag_1        NaN
Length: 73, dtype: float64
 
Number of lag :  18
R-squared :  1.0
P-value : 
chg_oil_spot_WTI_Positive   NaN
chg_oil_spot_WTI_Negative   NaN
chg_gdp_us                  NaN
chg_gdp_china               NaN
chg_gdp_europe              NaN
                             ..
chg_gdp_europe_lag_2        NaN
chg_oil_spot_WTI_lag_1      NaN
chg_gdp_us_lag_1            NaN
chg_gdp_china_lag_1         NaN
chg_gdp_europe_lag_1        NaN
Length: 77, dtype: float64
 
Number of lag :  19
C:\Users\DELL\Anaconda3\lib\site-packages\statsmodels\regression\linear_model.py:1510: RuntimeWarning: divide by zero encountered in double_scalars
  return np.dot(wresid, wresid) / self.df_resid
C:\Users\DELL\Anaconda3\lib\site-packages\statsmodels\regression\linear_model.py:1510: RuntimeWarning: divide by zero encountered in double_scalars
  return np.dot(wresid, wresid) / self.df_resid
R-squared :  1.0
P-value : 
chg_oil_spot_WTI_Positive   NaN
chg_oil_spot_WTI_Negative   NaN
chg_gdp_us                  NaN
chg_gdp_china               NaN
chg_gdp_europe              NaN
                             ..
chg_gdp_europe_lag_2        NaN
chg_oil_spot_WTI_lag_1      NaN
chg_gdp_us_lag_1            NaN
chg_gdp_china_lag_1         NaN
chg_gdp_europe_lag_1        NaN
Length: 81, dtype: float64
 
Number of lag :  20
R-squared :  1.0
P-value : 
chg_oil_spot_WTI_Positive   NaN
chg_oil_spot_WTI_Negative   NaN
chg_gdp_us                  NaN
chg_gdp_china               NaN
chg_gdp_europe              NaN
                             ..
chg_gdp_europe_lag_2        NaN
chg_oil_spot_WTI_lag_1      NaN
chg_gdp_us_lag_1            NaN
chg_gdp_china_lag_1         NaN
chg_gdp_europe_lag_1        NaN
Length: 85, dtype: float64
 
C:\Users\DELL\Anaconda3\lib\site-packages\statsmodels\regression\linear_model.py:1510: RuntimeWarning: divide by zero encountered in double_scalars
  return np.dot(wresid, wresid) / self.df_resid

Yearly change oil price with 1 lag is a best predictor to yearly change CO2 concentration

5.) Monthly analysis: Monthly data generates very low R squared

In [144]:
dummy_list = oil_co2_df['average']
oil_co2_df.drop(columns = 'average')
oil_co2_df['co2_conc'] = dummy_list
In [145]:
first_dif_conc = (np.log(oil_co2_df['co2_conc'].shift(1)) - np.log(oil_co2_df['co2_conc'].shift(0)))
oil_co2_df['chg_co2_conc'] = first_dif_conc
In [146]:
import matplotlib.pyplot as plt

fig,ax1 = plt.subplots(figsize = (15,8))

ax1.plot(oil_co2_df.Date,oil_co2_df['average'],color = 'tab:red')

ax2 = ax1.twinx() 

ax2.plot(oil_co2_df.Date,oil_co2_df[ 'oil_spot_WTI'],color = 'tab:blue')
Out[146]:
[<matplotlib.lines.Line2D at 0x1534cb17c18>]
In [147]:
import matplotlib.pyplot as plt

fig,ax1 = plt.subplots(figsize = (15,8))

ax1.plot(oil_co2_df.Date,oil_co2_df['chg_oil_spot_WTI'],color = 'tab:red')

ax2 = ax1.twinx() 

ax2.plot(oil_co2_df.Date,oil_co2_df['chg_co2_conc'],color = 'tab:blue')
Out[147]:
[<matplotlib.lines.Line2D at 0x1534ef1eef0>]
In [148]:
# test perfect number of lags used in model
import statsmodels.api as sm

nlag = 20

for i in range(nlag+1):
    #print(i)
    oil_co2_df_loop = oil_co2_df.copy()
    #running = i.copy()
    column_names = ['chg_oil_spot_WTI']
    print("Number of lag : ", str(i))
    while i > 0:
        text = 'lag' + '_' + str(i)
        oil_co2_df_loop[text] = oil_co2_df['chg_oil_spot_WTI'].shift(i)
        column_names.append(text)
        i = i - 1
        #print(i+1)
    #print(" ")
    oil_co2_df_loop = oil_co2_df_loop.dropna()
    
    x = oil_co2_df_loop[column_names] 
    reg_model = sm.OLS(oil_co2_df_loop['chg_co2_conc'],x)
    result = reg_model.fit()
    print("R-squared : ", result.rsquared)
    print("P-value : ")
    print(result.pvalues)
    print(" ")
Number of lag :  0
R-squared :  0.0020501677901554327
P-value : 
chg_oil_spot_WTI    0.309861
dtype: float64
 
Number of lag :  1
R-squared :  0.00340744689190986
P-value : 
chg_oil_spot_WTI    0.328394
lag_1               0.408714
dtype: float64
 
Number of lag :  2
R-squared :  0.0038387674084499057
P-value : 
chg_oil_spot_WTI    0.321194
lag_2               0.641596
lag_1               0.435043
dtype: float64
 
Number of lag :  3
R-squared :  0.003910075951151226
P-value : 
chg_oil_spot_WTI    0.319911
lag_3               0.850018
lag_2               0.640647
lag_1               0.445493
dtype: float64
 
Number of lag :  4
R-squared :  0.006858858461471273
P-value : 
chg_oil_spot_WTI    0.404522
lag_4               0.224099
lag_3               0.828001
lag_2               0.608460
lag_1               0.458532
dtype: float64
 
Number of lag :  5
R-squared :  0.010169475672391015
P-value : 
chg_oil_spot_WTI    0.365251
lag_5               0.197444
lag_4               0.331249
lag_3               0.849650
lag_2               0.635354
lag_1               0.516317
dtype: float64
 
Number of lag :  6
R-squared :  0.010172134495215479
P-value : 
chg_oil_spot_WTI    0.370583
lag_6               0.970868
lag_5               0.199957
lag_4               0.334816
lag_3               0.853113
lag_2               0.637568
lag_1               0.518098
dtype: float64
 
Number of lag :  7
R-squared :  0.010762728959098578
P-value : 
chg_oil_spot_WTI    0.377467
lag_7               0.586568
lag_6               0.944246
lag_5               0.224896
lag_4               0.314486
lag_3               0.827628
lag_2               0.634603
lag_1               0.543493
dtype: float64
 
Number of lag :  8
R-squared :  0.01088100288538374
P-value : 
chg_oil_spot_WTI    0.369167
lag_8               0.807882
lag_7               0.597507
lag_6               0.991604
lag_5               0.224303
lag_4               0.301358
lag_3               0.814276
lag_2               0.631809
lag_1               0.542851
dtype: float64
 
Number of lag :  9
R-squared :  0.0198072087688973
P-value : 
chg_oil_spot_WTI    0.344695
lag_9               0.034419
lag_8               0.910395
lag_7               0.285508
lag_6               0.824437
lag_5               0.461929
lag_4               0.298688
lag_3               0.783957
lag_2               0.556197
lag_1               0.600539
dtype: float64
 
Number of lag :  10
R-squared :  0.02654666648695292
P-value : 
chg_oil_spot_WTI    0.290149
lag_10              0.065277
lag_9               0.031859
lag_8               0.974962
lag_7               0.247071
lag_6               0.925135
lag_5               0.593577
lag_4               0.344604
lag_3               0.900368
lag_2               0.638810
lag_1               0.550205
dtype: float64
 
Number of lag :  11
R-squared :  0.026890109375713345
P-value : 
chg_oil_spot_WTI    0.294222
lag_11              0.677076
lag_10              0.068788
lag_9               0.033535
lag_8               0.988128
lag_7               0.288127
lag_6               0.969371
lag_5               0.609811
lag_4               0.331098
lag_3               0.872263
lag_2               0.639944
lag_1               0.522877
dtype: float64
 
Number of lag :  12
R-squared :  0.028440719723253904
P-value : 
chg_oil_spot_WTI    0.261496
lag_12              0.376464
lag_11              0.668284
lag_10              0.056850
lag_9               0.038264
lag_8               0.844079
lag_7               0.322273
lag_6               0.951770
lag_5               0.588931
lag_4               0.350687
lag_3               0.896602
lag_2               0.555988
lag_1               0.534368
dtype: float64
 
Number of lag :  13
R-squared :  0.02941122495753734
P-value : 
chg_oil_spot_WTI    0.271576
lag_13              0.484278
lag_12              0.413733
lag_11              0.596247
lag_10              0.071797
lag_9               0.049337
lag_8               0.879013
lag_7               0.330878
lag_6               0.990550
lag_5               0.614741
lag_4               0.318077
lag_3               0.953956
lag_2               0.554912
lag_1               0.508191
dtype: float64
 
Number of lag :  14
R-squared :  0.03290706849569036
P-value : 
chg_oil_spot_WTI    0.281181
lag_14              0.184295
lag_13              0.318815
lag_12              0.493443
lag_11              0.508577
lag_10              0.070966
lag_9               0.063735
lag_8               0.951520
lag_7               0.424822
lag_6               0.971903
lag_5               0.661287
lag_4               0.330232
lag_3               0.909668
lag_2               0.614788
lag_1               0.490008
dtype: float64
 
Number of lag :  15
R-squared :  0.03913653069042311
P-value : 
chg_oil_spot_WTI    0.271267
lag_15              0.075910
lag_14              0.156101
lag_13              0.387121
lag_12              0.408928
lag_11              0.583481
lag_10              0.073093
lag_9               0.146180
lag_8               0.930625
lag_7               0.630043
lag_6               0.994839
lag_5               0.501993
lag_4               0.382480
lag_3               0.947703
lag_2               0.641582
lag_1               0.491952
dtype: float64
 
Number of lag :  16
R-squared :  0.04019162816113486
P-value : 
chg_oil_spot_WTI    0.267835
lag_16              0.464719
lag_15              0.059869
lag_14              0.141438
lag_13              0.392740
lag_12              0.446797
lag_11              0.580104
lag_10              0.098965
lag_9               0.164136
lag_8               0.857020
lag_7               0.661641
lag_6               0.920704
lag_5               0.527253
lag_4               0.355103
lag_3               0.940554
lag_2               0.642655
lag_1               0.496924
dtype: float64
 
Number of lag :  17
R-squared :  0.04627943197759421
P-value : 
chg_oil_spot_WTI    0.289037
lag_17              0.078813
lag_16              0.385920
lag_15              0.034125
lag_14              0.107524
lag_13              0.532184
lag_12              0.389394
lag_11              0.617660
lag_10              0.078173
lag_9               0.215789
lag_8               0.935590
lag_7               0.583996
lag_6               0.867141
lag_5               0.501538
lag_4               0.358088
lag_3               0.840822
lag_2               0.609498
lag_1               0.446450
dtype: float64
 
Number of lag :  18
R-squared :  0.04646346324997075
P-value : 
chg_oil_spot_WTI    0.290767
lag_18              0.759775
lag_17              0.086160
lag_16              0.367996
lag_15              0.032808
lag_14              0.103922
lag_13              0.533297
lag_12              0.398816
lag_11              0.600829
lag_10              0.083223
lag_9               0.207229
lag_8               0.941910
lag_7               0.573474
lag_6               0.853244
lag_5               0.517093
lag_4               0.350736
lag_3               0.828709
lag_2               0.596797
lag_1               0.448063
dtype: float64
 
Number of lag :  19
R-squared :  0.04858168325217538
P-value : 
chg_oil_spot_WTI    0.280068
lag_19              0.299760
lag_18              0.754093
lag_17              0.098210
lag_16              0.289423
lag_15              0.034527
lag_14              0.091219
lag_13              0.639431
lag_12              0.379005
lag_11              0.723743
lag_10              0.081082
lag_9               0.176880
lag_8               0.879716
lag_7               0.522491
lag_6               0.868703
lag_5               0.531713
lag_4               0.326933
lag_3               0.809429
lag_2               0.570404
lag_1               0.477778
dtype: float64
 
Number of lag :  20
R-squared :  0.04949517419831351
P-value : 
chg_oil_spot_WTI    0.267611
lag_20              0.495998
lag_19              0.272978
lag_18              0.852672
lag_17              0.095134
lag_16              0.338975
lag_15              0.039740
lag_14              0.080620
lag_13              0.634204
lag_12              0.445421
lag_11              0.763599
lag_10              0.067556
lag_9               0.188963
lag_8               0.939650
lag_7               0.509767
lag_6               0.865918
lag_5               0.534010
lag_4               0.316330
lag_3               0.815867
lag_2               0.588328
lag_1               0.470876
dtype: float64
 
Monthly data generates very low R squared

6. Final analysis on exploratory data

In [149]:
#Weekly gasoline
analysis = oil_co2_df.copy()
oil_co2_df.columns
Out[149]:
Index(['Weekindex', 'Date', 'Year', 'Month', 'Week', 'Day', 'Par_Month',
       'Par_Day', 'oil_spot_WTI', 'oil_spot_Brent', 'future_oil_contract_1',
       'sugar_price_us', 'ethanol_price_us', 'chg_oil_spot_WTI',
       'chg_oil_spot_Brent', 'chg_oil_spot_WTI_Positive',
       'chg_oil_spot_WTI_Negative', 'chg_oil_future_contract1',
       'chg_oil_future_contract1_Positive',
       'chg_oil_future_contract1_Negative', 'Gasoline_Price_US',
       'chg_Gasoline_price_US', 'chg_Gasoline_price_US_Positive',
       'chg_Gasoline_price_US_future', 'Date_edited', 'year', 'month', 'day',
       'decimal', 'average', 'ndays', '1_year_ago', '10_years_ago',
       'increase_since_1800', 'co2_conc', 'chg_co2_conc'],
      dtype='object')
In [150]:
analysis = analysis[['chg_oil_spot_WTI_Positive','chg_oil_spot_WTI_Negative','chg_Gasoline_price_US','chg_co2_conc']].dropna(subset = ['chg_co2_conc'])
In [151]:
### Weekly ###
analysis_reg = analysis.copy()

#input_df_reg['positive_change'] = list(map(lambda x : 0 if x <= 0 else x,input_df['World_Emission_general'] ))
#input_df_reg['negative_change'] = list(map(lambda x : 0 if x >= 0 else x,input_df['World_Emission_general'] ))


analysis_reg['p+_lag1'] = analysis['chg_oil_spot_WTI_Positive'].shift(1)
analysis_reg['p+_lag2'] = analysis['chg_oil_spot_WTI_Positive'].shift(2)
analysis_reg['p+_lag3'] = analysis['chg_oil_spot_WTI_Positive'].shift(3)
analysis_reg['p+_lag4'] = analysis['chg_oil_spot_WTI_Positive'].shift(4)
analysis_reg['p+_lag5'] = analysis['chg_oil_spot_WTI_Positive'].shift(5)
analysis_reg['p+_lag6'] = analysis['chg_oil_spot_WTI_Positive'].shift(6)
analysis_reg['p+_lag7'] = analysis['chg_oil_spot_WTI_Positive'].shift(7)
analysis_reg['p+_lag8'] = analysis['chg_oil_spot_WTI_Positive'].shift(8)
analysis_reg['p+_lag9'] = analysis['chg_oil_spot_WTI_Positive'].shift(9)
analysis_reg['p+_lag10'] = analysis['chg_oil_spot_WTI_Positive'].shift(10)

analysis_reg['p-_lag1'] = analysis['chg_oil_spot_WTI_Negative'].shift(1)
analysis_reg['p-_lag2'] = analysis['chg_oil_spot_WTI_Negative'].shift(2)
analysis_reg['p-_lag3'] = analysis['chg_oil_spot_WTI_Negative'].shift(3)
analysis_reg['p-_lag4'] = analysis['chg_oil_spot_WTI_Negative'].shift(4)
analysis_reg['p-_lag5'] = analysis['chg_oil_spot_WTI_Negative'].shift(5)
analysis_reg['p-_lag6'] = analysis['chg_oil_spot_WTI_Negative'].shift(6)
analysis_reg['p-_lag7'] = analysis['chg_oil_spot_WTI_Negative'].shift(7)
analysis_reg['p-_lag8'] = analysis['chg_oil_spot_WTI_Negative'].shift(8)
analysis_reg['p-_lag9'] = analysis['chg_oil_spot_WTI_Negative'].shift(9)
analysis_reg['p-_lag10'] = analysis['chg_oil_spot_WTI_Negative'].shift(10)


analysis_reg = analysis_reg.dropna()
In [152]:
#Weekly gasoline
x = analysis_reg[['chg_oil_spot_WTI_Positive', 'chg_oil_spot_WTI_Negative','p+_lag1', 'p+_lag2',
       'p+_lag3', 'p+_lag4', 'p+_lag5', 'p+_lag6', 'p+_lag7', 'p+_lag8',
       'p+_lag9', 'p+_lag10', 'p-_lag1', 'p-_lag2', 'p-_lag3', 'p-_lag4',
       'p-_lag5', 'p-_lag6', 'p-_lag7', 'p-_lag8', 'p-_lag9', 'p-_lag10']]

reg_model = sm.OLS(analysis_reg['chg_Gasoline_price_US'],x)
result = reg_model.fit()
print(result.summary())
## Three years of emissions
                              OLS Regression Results                             
=================================================================================
Dep. Variable:     chg_Gasoline_price_US   R-squared:                       0.209
Model:                               OLS   Adj. R-squared:                  0.190
Method:                    Least Squares   F-statistic:                     11.07
Date:                   Sun, 28 Feb 2021   Prob (F-statistic):           2.73e-34
Time:                           15:24:56   Log-Likelihood:                 2424.9
No. Observations:                    943   AIC:                            -4806.
Df Residuals:                        921   BIC:                            -4699.
Df Model:                             22                                         
Covariance Type:               nonrobust                                         
=============================================================================================
                                coef    std err          t      P>|t|      [0.025      0.975]
---------------------------------------------------------------------------------------------
chg_oil_spot_WTI_Positive     0.0035      0.021      0.166      0.868      -0.038       0.045
chg_oil_spot_WTI_Negative     0.0724      0.018      3.926      0.000       0.036       0.109
p+_lag1                       0.0900      0.021      4.220      0.000       0.048       0.132
p+_lag2                       0.0708      0.021      3.319      0.001       0.029       0.113
p+_lag3                       0.0205      0.021      0.962      0.336      -0.021       0.062
p+_lag4                       0.0458      0.021      2.163      0.031       0.004       0.087
p+_lag5                       0.0134      0.021      0.632      0.528      -0.028       0.055
p+_lag6                       0.0314      0.021      1.497      0.135      -0.010       0.073
p+_lag7                      -0.0042      0.021     -0.199      0.842      -0.045       0.037
p+_lag8                       0.0305      0.021      1.466      0.143      -0.010       0.071
p+_lag9                       0.0203      0.020      1.034      0.301      -0.018       0.059
p+_lag10                      0.0070      0.019      0.368      0.713      -0.030       0.044
p-_lag1                       0.1011      0.019      5.247      0.000       0.063       0.139
p-_lag2                       0.1170      0.020      5.761      0.000       0.077       0.157
p-_lag3                       0.0437      0.020      2.133      0.033       0.003       0.084
p-_lag4                       0.0022      0.021      0.105      0.916      -0.038       0.042
p-_lag5                      -0.0207      0.021     -1.004      0.316      -0.061       0.020
p-_lag6                      -0.0416      0.021     -2.024      0.043      -0.082      -0.001
p-_lag7                      -0.0319      0.021     -1.535      0.125      -0.073       0.009
p-_lag8                      -0.0027      0.021     -0.130      0.896      -0.043       0.038
p-_lag9                       0.0066      0.020      0.323      0.747      -0.033       0.047
p-_lag10                      0.0125      0.020      0.621      0.535      -0.027       0.052
==============================================================================
Omnibus:                      231.030   Durbin-Watson:                   1.248
Prob(Omnibus):                  0.000   Jarque-Bera (JB):             2982.284
Skew:                           0.734   Prob(JB):                         0.00
Kurtosis:                      11.588   Cond. No.                         5.10
==============================================================================

Warnings:
[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.
In [153]:
result.tvalues.to_frame()
Out[153]:
0
chg_oil_spot_WTI_Positive 0.166232
chg_oil_spot_WTI_Negative 3.925770
p+_lag1 4.219909
p+_lag2 3.318751
p+_lag3 0.962067
p+_lag4 2.162696
p+_lag5 0.631988
p+_lag6 1.496881
p+_lag7 -0.198889
p+_lag8 1.465689
p+_lag9 1.033833
p+_lag10 0.367617
p-_lag1 5.247461
p-_lag2 5.761210
p-_lag3 2.132943
p-_lag4 0.104996
p-_lag5 -1.004217
p-_lag6 -2.023980
p-_lag7 -1.535311
p-_lag8 -0.130209
p-_lag9 0.322853
p-_lag10 0.620932
In [154]:
#Weekly
analysis = oil_co2_df.copy()
oil_co2_df.columns
Out[154]:
Index(['Weekindex', 'Date', 'Year', 'Month', 'Week', 'Day', 'Par_Month',
       'Par_Day', 'oil_spot_WTI', 'oil_spot_Brent', 'future_oil_contract_1',
       'sugar_price_us', 'ethanol_price_us', 'chg_oil_spot_WTI',
       'chg_oil_spot_Brent', 'chg_oil_spot_WTI_Positive',
       'chg_oil_spot_WTI_Negative', 'chg_oil_future_contract1',
       'chg_oil_future_contract1_Positive',
       'chg_oil_future_contract1_Negative', 'Gasoline_Price_US',
       'chg_Gasoline_price_US', 'chg_Gasoline_price_US_Positive',
       'chg_Gasoline_price_US_future', 'Date_edited', 'year', 'month', 'day',
       'decimal', 'average', 'ndays', '1_year_ago', '10_years_ago',
       'increase_since_1800', 'co2_conc', 'chg_co2_conc'],
      dtype='object')
In [155]:
analysis = analysis[['chg_oil_spot_WTI_Positive','chg_oil_spot_WTI_Negative','chg_Gasoline_price_US','chg_co2_conc']].dropna(subset = ['chg_co2_conc'])
In [156]:
### Weekly ###
analysis_reg = analysis.copy()

#input_df_reg['positive_change'] = list(map(lambda x : 0 if x <= 0 else x,input_df['World_Emission_general'] ))
#input_df_reg['negative_change'] = list(map(lambda x : 0 if x >= 0 else x,input_df['World_Emission_general'] ))


analysis_reg['p+_lag1'] = analysis['chg_oil_spot_WTI_Positive'].shift(1)
analysis_reg['p+_lag2'] = analysis['chg_oil_spot_WTI_Positive'].shift(2)
analysis_reg['p+_lag3'] = analysis['chg_oil_spot_WTI_Positive'].shift(3)
analysis_reg['p+_lag4'] = analysis['chg_oil_spot_WTI_Positive'].shift(4)
analysis_reg['p+_lag5'] = analysis['chg_oil_spot_WTI_Positive'].shift(5)
analysis_reg['p+_lag6'] = analysis['chg_oil_spot_WTI_Positive'].shift(6)
analysis_reg['p+_lag7'] = analysis['chg_oil_spot_WTI_Positive'].shift(7)
analysis_reg['p+_lag8'] = analysis['chg_oil_spot_WTI_Positive'].shift(8)
analysis_reg['p+_lag9'] = analysis['chg_oil_spot_WTI_Positive'].shift(9)
analysis_reg['p+_lag10'] = analysis['chg_oil_spot_WTI_Positive'].shift(10)

analysis_reg['p-_lag1'] = analysis['chg_oil_spot_WTI_Negative'].shift(1)
analysis_reg['p-_lag2'] = analysis['chg_oil_spot_WTI_Negative'].shift(2)
analysis_reg['p-_lag3'] = analysis['chg_oil_spot_WTI_Negative'].shift(3)
analysis_reg['p-_lag4'] = analysis['chg_oil_spot_WTI_Negative'].shift(4)
analysis_reg['p-_lag5'] = analysis['chg_oil_spot_WTI_Negative'].shift(5)
analysis_reg['p-_lag6'] = analysis['chg_oil_spot_WTI_Negative'].shift(6)
analysis_reg['p-_lag7'] = analysis['chg_oil_spot_WTI_Negative'].shift(7)
analysis_reg['p-_lag8'] = analysis['chg_oil_spot_WTI_Negative'].shift(8)
analysis_reg['p-_lag9'] = analysis['chg_oil_spot_WTI_Negative'].shift(9)
analysis_reg['p-_lag10'] = analysis['chg_oil_spot_WTI_Negative'].shift(10)


analysis_reg = analysis_reg.dropna()
In [157]:
#Weekly CO2
x = analysis_reg[['chg_oil_spot_WTI_Positive', 'chg_oil_spot_WTI_Negative','p+_lag1', 'p+_lag2',
       'p+_lag3', 'p+_lag4', 'p+_lag5', 'p+_lag6', 'p+_lag7', 'p+_lag8',
       'p+_lag9', 'p+_lag10', 'p-_lag1', 'p-_lag2', 'p-_lag3', 'p-_lag4',
       'p-_lag5', 'p-_lag6', 'p-_lag7', 'p-_lag8', 'p-_lag9', 'p-_lag10']]

reg_model = sm.OLS(analysis_reg['chg_co2_conc'],x)
result = reg_model.fit()
print(result.summary())
## Three years of emissions
                            OLS Regression Results                            
==============================================================================
Dep. Variable:           chg_co2_conc   R-squared:                       0.031
Model:                            OLS   Adj. R-squared:                  0.007
Method:                 Least Squares   F-statistic:                     1.320
Date:                Sun, 28 Feb 2021   Prob (F-statistic):              0.148
Time:                        15:24:56   Log-Likelihood:                 4796.8
No. Observations:                 943   AIC:                            -9550.
Df Residuals:                     921   BIC:                            -9443.
Df Model:                          22                                         
Covariance Type:            nonrobust                                         
=============================================================================================
                                coef    std err          t      P>|t|      [0.025      0.975]
---------------------------------------------------------------------------------------------
chg_oil_spot_WTI_Positive     0.0002      0.002      0.116      0.908      -0.003       0.004
chg_oil_spot_WTI_Negative     0.0032      0.001      2.115      0.035       0.000       0.006
p+_lag1                    4.766e-05      0.002      0.028      0.978      -0.003       0.003
p+_lag2                       0.0017      0.002      0.966      0.334      -0.002       0.005
p+_lag3                       0.0002      0.002      0.121      0.904      -0.003       0.004
p+_lag4                      -0.0020      0.002     -1.164      0.245      -0.005       0.001
p+_lag5                       0.0004      0.002      0.247      0.805      -0.003       0.004
p+_lag6                      -0.0003      0.002     -0.171      0.864      -0.004       0.003
p+_lag7                      -0.0002      0.002     -0.132      0.895      -0.004       0.003
p+_lag8                       0.0009      0.002      0.546      0.585      -0.002       0.004
p+_lag9                      -0.0009      0.002     -0.587      0.558      -0.004       0.002
p+_lag10                      0.0030      0.002      1.927      0.054   -5.49e-05       0.006
p-_lag1                       0.0016      0.002      1.027      0.305      -0.001       0.005
p-_lag2                       0.0025      0.002      1.521      0.129      -0.001       0.006
p-_lag3                       0.0008      0.002      0.501      0.617      -0.002       0.004
p-_lag4                       0.0005      0.002      0.305      0.761      -0.003       0.004
p-_lag5                      -0.0001      0.002     -0.067      0.947      -0.003       0.003
p-_lag6                       0.0006      0.002      0.356      0.722      -0.003       0.004
p-_lag7                       0.0002      0.002      0.097      0.923      -0.003       0.003
p-_lag8                   -5.794e-06      0.002     -0.003      0.997      -0.003       0.003
p-_lag9                    6.211e-05      0.002      0.038      0.970      -0.003       0.003
p-_lag10                     -0.0013      0.002     -0.794      0.428      -0.004       0.002
==============================================================================
Omnibus:                       11.994   Durbin-Watson:                   1.945
Prob(Omnibus):                  0.002   Jarque-Bera (JB):               17.186
Skew:                           0.109   Prob(JB):                     0.000185
Kurtosis:                       3.625   Cond. No.                         5.10
==============================================================================

Warnings:
[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.
In [158]:
result.tvalues.to_frame()
Out[158]:
0
chg_oil_spot_WTI_Positive 0.115751
chg_oil_spot_WTI_Negative 2.114504
p+_lag1 0.027654
p+_lag2 0.965929
p+_lag3 0.120615
p+_lag4 -1.164309
p+_lag5 0.247266
p+_lag6 -0.171416
p+_lag7 -0.132262
p+_lag8 0.546003
p+_lag9 -0.586714
p+_lag10 1.926912
p-_lag1 1.026983
p-_lag2 1.520770
p-_lag3 0.500548
p-_lag4 0.304744
p-_lag5 -0.066886
p-_lag6 0.356035
p-_lag7 0.097084
p-_lag8 -0.003496
p-_lag9 0.037613
p-_lag10 -0.793567
In [159]:
#Weekly oil futures to future gasoline price

#Weekly
analysis = oil_co2_df.copy()
oil_co2_df.columns
analysis = analysis[['chg_oil_future_contract1_Positive','chg_oil_future_contract1_Negative','chg_Gasoline_price_US','chg_co2_conc']].dropna(subset = ['chg_co2_conc'])



analysis_reg = analysis.copy()

#input_df_reg['positive_change'] = list(map(lambda x : 0 if x <= 0 else x,input_df['World_Emission_general'] ))
#input_df_reg['negative_change'] = list(map(lambda x : 0 if x >= 0 else x,input_df['World_Emission_general'] ))


analysis_reg['p+_lag1'] = analysis['chg_oil_future_contract1_Positive'].shift(1)
analysis_reg['p+_lag2'] = analysis['chg_oil_future_contract1_Positive'].shift(2)
analysis_reg['p+_lag3'] = analysis['chg_oil_future_contract1_Positive'].shift(3)
analysis_reg['p+_lag4'] = analysis['chg_oil_future_contract1_Positive'].shift(4)
analysis_reg['p+_lag5'] = analysis['chg_oil_future_contract1_Positive'].shift(5)
analysis_reg['p+_lag6'] = analysis['chg_oil_future_contract1_Positive'].shift(6)
analysis_reg['p+_lag7'] = analysis['chg_oil_future_contract1_Positive'].shift(7)
analysis_reg['p+_lag8'] = analysis['chg_oil_future_contract1_Positive'].shift(8)
analysis_reg['p+_lag9'] = analysis['chg_oil_future_contract1_Positive'].shift(9)
analysis_reg['p+_lag10'] = analysis['chg_oil_future_contract1_Positive'].shift(10)

analysis_reg['chg_Future_gasoline'] = analysis['chg_Gasoline_price_US'].shift(-1)


analysis_reg['p-_lag1'] = analysis['chg_oil_future_contract1_Negative'].shift(1)
analysis_reg['p-_lag2'] = analysis['chg_oil_future_contract1_Negative'].shift(2)
analysis_reg['p-_lag3'] = analysis['chg_oil_future_contract1_Negative'].shift(3)
analysis_reg['p-_lag4'] = analysis['chg_oil_future_contract1_Negative'].shift(4)
analysis_reg['p-_lag5'] = analysis['chg_oil_future_contract1_Negative'].shift(5)
analysis_reg['p-_lag6'] = analysis['chg_oil_future_contract1_Negative'].shift(6)
analysis_reg['p-_lag7'] = analysis['chg_oil_future_contract1_Negative'].shift(7)
analysis_reg['p-_lag8'] = analysis['chg_oil_future_contract1_Negative'].shift(8)
analysis_reg['p-_lag9'] = analysis['chg_oil_future_contract1_Negative'].shift(9)
analysis_reg['p-_lag10'] = analysis['chg_oil_future_contract1_Negative'].shift(10)


analysis_reg = analysis_reg.dropna()


#Regression week oil futures to future gasoline price
x = analysis_reg[['chg_oil_future_contract1_Positive', 'chg_oil_future_contract1_Negative','p+_lag1', 'p+_lag2',
       'p+_lag3', 'p+_lag4', 'p+_lag5', 'p+_lag6', 'p+_lag7', 'p+_lag8',
       'p+_lag9', 'p+_lag10', 'p-_lag1', 'p-_lag2', 'p-_lag3', 'p-_lag4',
       'p-_lag5', 'p-_lag6', 'p-_lag7', 'p-_lag8', 'p-_lag9', 'p-_lag10']]

reg_model = sm.OLS(analysis_reg['chg_Future_gasoline'],x)
result = reg_model.fit()
print(result.summary())
## Three years of emissions
                             OLS Regression Results                            
===============================================================================
Dep. Variable:     chg_Future_gasoline   R-squared:                       0.208
Model:                             OLS   Adj. R-squared:                  0.189
Method:                  Least Squares   F-statistic:                     11.00
Date:                 Sun, 28 Feb 2021   Prob (F-statistic):           5.01e-34
Time:                         15:24:56   Log-Likelihood:                 2421.3
No. Observations:                  942   AIC:                            -4799.
Df Residuals:                      920   BIC:                            -4692.
Df Model:                           22                                         
Covariance Type:             nonrobust                                         
=====================================================================================================
                                        coef    std err          t      P>|t|      [0.025      0.975]
-----------------------------------------------------------------------------------------------------
chg_oil_future_contract1_Positive     0.0983      0.024      4.081      0.000       0.051       0.146
chg_oil_future_contract1_Negative     0.1330      0.020      6.759      0.000       0.094       0.172
p+_lag1                               0.0968      0.024      3.999      0.000       0.049       0.144
p+_lag2                               0.0306      0.024      1.265      0.206      -0.017       0.078
p+_lag3                               0.0208      0.024      0.856      0.392      -0.027       0.069
p+_lag4                               0.0180      0.024      0.741      0.459      -0.030       0.065
p+_lag5                               0.0216      0.024      0.893      0.372      -0.026       0.069
p+_lag6                              -0.0133      0.024     -0.555      0.579      -0.061       0.034
p+_lag7                               0.0184      0.024      0.774      0.439      -0.028       0.065
p+_lag8                              -0.0016      0.023     -0.068      0.946      -0.048       0.044
p+_lag9                              -0.0146      0.023     -0.637      0.525      -0.059       0.030
p+_lag10                              0.0336      0.023      1.484      0.138      -0.011       0.078
p-_lag1                               0.1206      0.020      5.990      0.000       0.081       0.160
p-_lag2                               0.0480      0.021      2.329      0.020       0.008       0.088
p-_lag3                               0.0116      0.021      0.556      0.578      -0.029       0.053
p-_lag4                              -0.0066      0.021     -0.310      0.756      -0.048       0.035
p-_lag5                              -0.0373      0.021     -1.756      0.079      -0.079       0.004
p-_lag6                              -0.0259      0.021     -1.221      0.222      -0.067       0.016
p-_lag7                              -0.0092      0.021     -0.433      0.665      -0.051       0.033
p-_lag8                               0.0101      0.021      0.480      0.631      -0.031       0.051
p-_lag9                               0.0242      0.021      1.153      0.249      -0.017       0.066
p-_lag10                             -0.0584      0.021     -2.788      0.005      -0.099      -0.017
==============================================================================
Omnibus:                      204.519   Durbin-Watson:                   1.236
Prob(Omnibus):                  0.000   Jarque-Bera (JB):             2639.577
Skew:                           0.596   Prob(JB):                         0.00
Kurtosis:                      11.113   Cond. No.                         4.89
==============================================================================

Warnings:
[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.
In [160]:
result.tvalues.to_frame()
Out[160]:
0
chg_oil_future_contract1_Positive 4.081454
chg_oil_future_contract1_Negative 6.758975
p+_lag1 3.999388
p+_lag2 1.264686
p+_lag3 0.855923
p+_lag4 0.741186
p+_lag5 0.892940
p+_lag6 -0.554530
p+_lag7 0.773687
p+_lag8 -0.068281
p+_lag9 -0.636584
p+_lag10 1.483553
p-_lag1 5.989742
p-_lag2 2.329403
p-_lag3 0.556118
p-_lag4 -0.310489
p-_lag5 -1.755664
p-_lag6 -1.221374
p-_lag7 -0.432766
p-_lag8 0.479867
p-_lag9 1.153025
p-_lag10 -2.788082
In [161]:
### Weekly ###
### Weekly Lag 0###

analysis = oil_co2_df.copy()

analysis = analysis[['chg_oil_spot_WTI_Positive','chg_oil_spot_WTI_Negative','chg_Gasoline_price_US','chg_co2_conc']].dropna(subset = ['chg_co2_conc'])
analysis_reg = analysis.copy()


analysis_reg = analysis_reg

x = analysis_reg[['chg_oil_spot_WTI_Positive', 'chg_oil_spot_WTI_Negative']] 

reg_model = sm.OLS(analysis_reg['chg_Gasoline_price_US'],x)
result = reg_model.fit()
print(result.summary())


### Weekly ###
### Weekly Lag 6###

analysis = oil_co2_df.copy()

analysis = analysis[['chg_oil_spot_WTI_Positive','chg_oil_spot_WTI_Negative','chg_Gasoline_price_US','chg_co2_conc']].dropna(subset = ['chg_co2_conc'])
analysis_reg = analysis.copy()


analysis_reg['p+_lag1'] = analysis['chg_oil_spot_WTI_Positive'].shift(1)
analysis_reg['p+_lag2'] = analysis['chg_oil_spot_WTI_Positive'].shift(2)
analysis_reg['p+_lag3'] = analysis['chg_oil_spot_WTI_Positive'].shift(3)
analysis_reg['p+_lag4'] = analysis['chg_oil_spot_WTI_Positive'].shift(4)
analysis_reg['p+_lag5'] = analysis['chg_oil_spot_WTI_Positive'].shift(5)
analysis_reg['p+_lag6'] = analysis['chg_oil_spot_WTI_Positive'].shift(6)

analysis_reg['p-_lag1'] = analysis['chg_oil_spot_WTI_Negative'].shift(1)
analysis_reg['p-_lag2'] = analysis['chg_oil_spot_WTI_Negative'].shift(2)
analysis_reg['p-_lag3'] = analysis['chg_oil_spot_WTI_Negative'].shift(3)
analysis_reg['p-_lag4'] = analysis['chg_oil_spot_WTI_Negative'].shift(4)
analysis_reg['p-_lag5'] = analysis['chg_oil_spot_WTI_Negative'].shift(5)
analysis_reg['p-_lag6'] = analysis['chg_oil_spot_WTI_Negative'].shift(6)


analysis_reg = analysis_reg.dropna(subset = ['p+_lag1','p-_lag1','p+_lag2','p-_lag2','p+_lag3','p-_lag3','p+_lag4','p-_lag4','p+_lag5','p-_lag5','p+_lag6','p-_lag6'])

x = analysis_reg[['chg_oil_spot_WTI_Positive', 'chg_oil_spot_WTI_Negative','p+_lag1','p-_lag1','p+_lag2','p-_lag2','p+_lag3','p-_lag3','p+_lag4','p-_lag4','p+_lag5','p-_lag5','p+_lag6','p-_lag6']] 

reg_model = sm.OLS(analysis_reg['chg_Gasoline_price_US'],x)
result = reg_model.fit()
print(result.summary())


### Weekly ###
### Weekly Lag 12###

analysis = oil_co2_df.copy()

analysis = analysis[['chg_oil_spot_WTI_Positive','chg_oil_spot_WTI_Negative','chg_Gasoline_price_US','chg_co2_conc']].dropna(subset = ['chg_co2_conc'])
analysis_reg = analysis.copy()

analysis_reg['p+_lag1'] = analysis['chg_oil_spot_WTI_Positive'].shift(1)
analysis_reg['p+_lag2'] = analysis['chg_oil_spot_WTI_Positive'].shift(2)
analysis_reg['p+_lag3'] = analysis['chg_oil_spot_WTI_Positive'].shift(3)
analysis_reg['p+_lag4'] = analysis['chg_oil_spot_WTI_Positive'].shift(4)
analysis_reg['p+_lag5'] = analysis['chg_oil_spot_WTI_Positive'].shift(5)
analysis_reg['p+_lag6'] = analysis['chg_oil_spot_WTI_Positive'].shift(6)
analysis_reg['p+_lag7'] = analysis['chg_oil_spot_WTI_Positive'].shift(7)
analysis_reg['p+_lag8'] = analysis['chg_oil_spot_WTI_Positive'].shift(8)
analysis_reg['p+_lag9'] = analysis['chg_oil_spot_WTI_Positive'].shift(9)
analysis_reg['p+_lag10'] = analysis['chg_oil_spot_WTI_Positive'].shift(10)
analysis_reg['p+_lag11'] = analysis['chg_oil_spot_WTI_Positive'].shift(11)
analysis_reg['p+_lag12'] = analysis['chg_oil_spot_WTI_Positive'].shift(12)

analysis_reg['p-_lag1'] = analysis['chg_oil_spot_WTI_Negative'].shift(1)
analysis_reg['p-_lag2'] = analysis['chg_oil_spot_WTI_Negative'].shift(2)
analysis_reg['p-_lag3'] = analysis['chg_oil_spot_WTI_Negative'].shift(3)
analysis_reg['p-_lag4'] = analysis['chg_oil_spot_WTI_Negative'].shift(4)
analysis_reg['p-_lag5'] = analysis['chg_oil_spot_WTI_Negative'].shift(5)
analysis_reg['p-_lag6'] = analysis['chg_oil_spot_WTI_Negative'].shift(6)
analysis_reg['p-_lag7'] = analysis['chg_oil_spot_WTI_Negative'].shift(7)
analysis_reg['p-_lag8'] = analysis['chg_oil_spot_WTI_Negative'].shift(8)
analysis_reg['p-_lag9'] = analysis['chg_oil_spot_WTI_Negative'].shift(9)
analysis_reg['p-_lag10'] = analysis['chg_oil_spot_WTI_Negative'].shift(10)
analysis_reg['p-_lag11'] = analysis['chg_oil_spot_WTI_Negative'].shift(11)
analysis_reg['p-_lag12'] = analysis['chg_oil_spot_WTI_Negative'].shift(12)


analysis_reg = analysis_reg.dropna(subset = ['p+_lag1','p-_lag1','p+_lag2','p-_lag2','p+_lag3','p-_lag3','p+_lag4','p-_lag4','p+_lag5','p-_lag5','p+_lag6','p-_lag6','p+_lag7','p-_lag7','p+_lag8','p-_lag8','p+_lag9','p-_lag9','p+_lag10','p-_lag10','p+_lag11','p-_lag11','p+_lag12','p-_lag12'])

x = analysis_reg[['chg_oil_spot_WTI_Positive', 'chg_oil_spot_WTI_Negative','p+_lag1','p-_lag1','p+_lag2','p-_lag2','p+_lag3','p-_lag3','p+_lag4','p-_lag4','p+_lag5','p-_lag5','p+_lag6','p-_lag6','p+_lag7','p-_lag7','p+_lag8','p-_lag8','p+_lag9','p-_lag9','p+_lag10','p-_lag10','p+_lag11','p-_lag11','p+_lag12','p-_lag12']] 

reg_model = sm.OLS(analysis_reg['chg_Gasoline_price_US'],x)
result = reg_model.fit()
print(result.summary())


### Weekly ###
### Weekly Lag 24###

analysis = oil_co2_df.copy()

analysis = analysis[['chg_oil_spot_WTI_Positive','chg_oil_spot_WTI_Negative','chg_Gasoline_price_US','chg_co2_conc']].dropna(subset = ['chg_co2_conc'])
analysis_reg = analysis.copy()

analysis_reg['p+_lag1'] = analysis['chg_oil_spot_WTI_Positive'].shift(1)
analysis_reg['p+_lag2'] = analysis['chg_oil_spot_WTI_Positive'].shift(2)
analysis_reg['p+_lag3'] = analysis['chg_oil_spot_WTI_Positive'].shift(3)
analysis_reg['p+_lag4'] = analysis['chg_oil_spot_WTI_Positive'].shift(4)
analysis_reg['p+_lag5'] = analysis['chg_oil_spot_WTI_Positive'].shift(5)
analysis_reg['p+_lag6'] = analysis['chg_oil_spot_WTI_Positive'].shift(6)
analysis_reg['p+_lag7'] = analysis['chg_oil_spot_WTI_Positive'].shift(7)
analysis_reg['p+_lag8'] = analysis['chg_oil_spot_WTI_Positive'].shift(8)
analysis_reg['p+_lag9'] = analysis['chg_oil_spot_WTI_Positive'].shift(9)
analysis_reg['p+_lag10'] = analysis['chg_oil_spot_WTI_Positive'].shift(10)
analysis_reg['p+_lag11'] = analysis['chg_oil_spot_WTI_Positive'].shift(11)
analysis_reg['p+_lag12'] = analysis['chg_oil_spot_WTI_Positive'].shift(12)
analysis_reg['p+_lag13'] = analysis['chg_oil_spot_WTI_Positive'].shift(13)
analysis_reg['p+_lag14'] = analysis['chg_oil_spot_WTI_Positive'].shift(14)
analysis_reg['p+_lag15'] = analysis['chg_oil_spot_WTI_Positive'].shift(15)
analysis_reg['p+_lag16'] = analysis['chg_oil_spot_WTI_Positive'].shift(16)
analysis_reg['p+_lag17'] = analysis['chg_oil_spot_WTI_Positive'].shift(17)
analysis_reg['p+_lag18'] = analysis['chg_oil_spot_WTI_Positive'].shift(18)
analysis_reg['p+_lag19'] = analysis['chg_oil_spot_WTI_Positive'].shift(19)
analysis_reg['p+_lag20'] = analysis['chg_oil_spot_WTI_Positive'].shift(20)
analysis_reg['p+_lag21'] = analysis['chg_oil_spot_WTI_Positive'].shift(21)
analysis_reg['p+_lag22'] = analysis['chg_oil_spot_WTI_Positive'].shift(22)
analysis_reg['p+_lag23'] = analysis['chg_oil_spot_WTI_Positive'].shift(23)
analysis_reg['p+_lag24'] = analysis['chg_oil_spot_WTI_Positive'].shift(24)

analysis_reg['p-_lag1'] = analysis['chg_oil_spot_WTI_Negative'].shift(1)
analysis_reg['p-_lag2'] = analysis['chg_oil_spot_WTI_Negative'].shift(2)
analysis_reg['p-_lag3'] = analysis['chg_oil_spot_WTI_Negative'].shift(3)
analysis_reg['p-_lag4'] = analysis['chg_oil_spot_WTI_Negative'].shift(4)
analysis_reg['p-_lag5'] = analysis['chg_oil_spot_WTI_Negative'].shift(5)
analysis_reg['p-_lag6'] = analysis['chg_oil_spot_WTI_Negative'].shift(6)
analysis_reg['p-_lag7'] = analysis['chg_oil_spot_WTI_Negative'].shift(7)
analysis_reg['p-_lag8'] = analysis['chg_oil_spot_WTI_Negative'].shift(8)
analysis_reg['p-_lag9'] = analysis['chg_oil_spot_WTI_Negative'].shift(9)
analysis_reg['p-_lag10'] = analysis['chg_oil_spot_WTI_Negative'].shift(10)
analysis_reg['p-_lag11'] = analysis['chg_oil_spot_WTI_Negative'].shift(11)
analysis_reg['p-_lag12'] = analysis['chg_oil_spot_WTI_Negative'].shift(12)
analysis_reg['p-_lag13'] = analysis['chg_oil_spot_WTI_Negative'].shift(13)
analysis_reg['p-_lag14'] = analysis['chg_oil_spot_WTI_Negative'].shift(14)
analysis_reg['p-_lag15'] = analysis['chg_oil_spot_WTI_Negative'].shift(15)
analysis_reg['p-_lag16'] = analysis['chg_oil_spot_WTI_Negative'].shift(16)
analysis_reg['p-_lag17'] = analysis['chg_oil_spot_WTI_Negative'].shift(17)
analysis_reg['p-_lag18'] = analysis['chg_oil_spot_WTI_Negative'].shift(18)
analysis_reg['p-_lag19'] = analysis['chg_oil_spot_WTI_Negative'].shift(19)
analysis_reg['p-_lag20'] = analysis['chg_oil_spot_WTI_Negative'].shift(20)
analysis_reg['p-_lag21'] = analysis['chg_oil_spot_WTI_Negative'].shift(21)
analysis_reg['p-_lag22'] = analysis['chg_oil_spot_WTI_Negative'].shift(22)
analysis_reg['p-_lag23'] = analysis['chg_oil_spot_WTI_Negative'].shift(23)
analysis_reg['p-_lag24'] = analysis['chg_oil_spot_WTI_Negative'].shift(24)


analysis_reg = analysis_reg.dropna(subset = ['p+_lag1','p-_lag1','p+_lag2','p-_lag2','p+_lag3','p-_lag3','p+_lag4','p-_lag4','p+_lag5','p-_lag5','p+_lag6','p-_lag6','p+_lag7','p-_lag7','p+_lag8','p-_lag8','p+_lag9','p-_lag9','p+_lag10','p-_lag10','p+_lag11','p-_lag11','p+_lag12','p-_lag12'
                                             ,'p+_lag13','p-_lag13','p+_lag14','p-_lag14','p+_lag15','p-_lag15','p+_lag16','p-_lag16','p+_lag17','p-_lag17','p+_lag18','p-_lag18','p+_lag19','p-_lag19','p+_lag20','p-_lag20','p+_lag21','p-_lag21','p+_lag22','p-_lag22','p+_lag23','p-_lag23','p+_lag24','p-_lag24'])

x = analysis_reg[['chg_oil_spot_WTI_Positive', 'chg_oil_spot_WTI_Negative','p+_lag1','p-_lag1','p+_lag2','p-_lag2','p+_lag3','p-_lag3','p+_lag4','p-_lag4','p+_lag5','p-_lag5','p+_lag6','p-_lag6','p+_lag7','p-_lag7','p+_lag8','p-_lag8','p+_lag9','p-_lag9','p+_lag10','p-_lag10','p+_lag11','p-_lag11','p+_lag12','p-_lag12'
                                             ,'p+_lag13','p-_lag13','p+_lag14','p-_lag14','p+_lag15','p-_lag15','p+_lag16','p-_lag16','p+_lag17','p-_lag17','p+_lag18','p-_lag18','p+_lag19','p-_lag19','p+_lag20','p-_lag20','p+_lag21','p-_lag21','p+_lag22','p-_lag22','p+_lag23','p-_lag23','p+_lag24','p-_lag24']] 

reg_model = sm.OLS(analysis_reg['chg_Gasoline_price_US'],x)
result = reg_model.fit()
print(result.summary())
                              OLS Regression Results                             
=================================================================================
Dep. Variable:     chg_Gasoline_price_US   R-squared:                       0.015
Model:                               OLS   Adj. R-squared:                  0.013
Method:                    Least Squares   F-statistic:                     7.314
Date:                   Sun, 28 Feb 2021   Prob (F-statistic):           0.000704
Time:                           15:24:56   Log-Likelihood:                 2346.5
No. Observations:                    953   AIC:                            -4689.
Df Residuals:                        951   BIC:                            -4679.
Df Model:                              2                                         
Covariance Type:               nonrobust                                         
=============================================================================================
                                coef    std err          t      P>|t|      [0.025      0.975]
---------------------------------------------------------------------------------------------
chg_oil_spot_WTI_Positive     0.0009      0.017      0.056      0.955      -0.032       0.034
chg_oil_spot_WTI_Negative     0.0606      0.016      3.824      0.000       0.030       0.092
==============================================================================
Omnibus:                      167.822   Durbin-Watson:                   1.120
Prob(Omnibus):                  0.000   Jarque-Bera (JB):             1503.749
Skew:                           0.515   Prob(JB):                         0.00
Kurtosis:                       9.067   Cond. No.                         1.06
==============================================================================

Warnings:
[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.
                              OLS Regression Results                             
=================================================================================
Dep. Variable:     chg_Gasoline_price_US   R-squared:                       0.202
Model:                               OLS   Adj. R-squared:                  0.190
Method:                    Least Squares   F-statistic:                     16.89
Date:                   Sun, 28 Feb 2021   Prob (F-statistic):           1.84e-37
Time:                           15:24:56   Log-Likelihood:                 2432.8
No. Observations:                    947   AIC:                            -4838.
Df Residuals:                        933   BIC:                            -4770.
Df Model:                             14                                         
Covariance Type:               nonrobust                                         
=============================================================================================
                                coef    std err          t      P>|t|      [0.025      0.975]
---------------------------------------------------------------------------------------------
chg_oil_spot_WTI_Positive     0.0128      0.021      0.624      0.533      -0.028       0.053
chg_oil_spot_WTI_Negative     0.0690      0.018      3.780      0.000       0.033       0.105
p+_lag1                       0.0936      0.021      4.512      0.000       0.053       0.134
p-_lag1                       0.1021      0.019      5.329      0.000       0.064       0.140
p+_lag2                       0.0770      0.021      3.721      0.000       0.036       0.118
p-_lag2                       0.1152      0.020      5.715      0.000       0.076       0.155
p+_lag3                       0.0226      0.020      1.106      0.269      -0.018       0.063
p-_lag3                       0.0452      0.020      2.231      0.026       0.005       0.085
p+_lag4                       0.0537      0.020      2.631      0.009       0.014       0.094
p-_lag4                       0.0014      0.020      0.071      0.943      -0.038       0.041
p+_lag5                       0.0282      0.019      1.462      0.144      -0.010       0.066
p-_lag5                      -0.0198      0.020     -0.987      0.324      -0.059       0.020
p+_lag6                       0.0412      0.019      2.215      0.027       0.005       0.078
p-_lag6                      -0.0452      0.020     -2.289      0.022      -0.084      -0.006
==============================================================================
Omnibus:                      223.899   Durbin-Watson:                   1.256
Prob(Omnibus):                  0.000   Jarque-Bera (JB):             2644.414
Skew:                           0.722   Prob(JB):                         0.00
Kurtosis:                      11.058   Cond. No.                         4.02
==============================================================================

Warnings:
[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.
                              OLS Regression Results                             
=================================================================================
Dep. Variable:     chg_Gasoline_price_US   R-squared:                       0.214
Model:                               OLS   Adj. R-squared:                  0.192
Method:                    Least Squares   F-statistic:                     9.610
Date:                   Sun, 28 Feb 2021   Prob (F-statistic):           2.34e-33
Time:                           15:24:56   Log-Likelihood:                 2422.4
No. Observations:                    941   AIC:                            -4793.
Df Residuals:                        915   BIC:                            -4667.
Df Model:                             26                                         
Covariance Type:               nonrobust                                         
=============================================================================================
                                coef    std err          t      P>|t|      [0.025      0.975]
---------------------------------------------------------------------------------------------
chg_oil_spot_WTI_Positive     0.0057      0.021      0.270      0.787      -0.036       0.047
chg_oil_spot_WTI_Negative     0.0732      0.018      3.958      0.000       0.037       0.109
p+_lag1                       0.0935      0.021      4.364      0.000       0.051       0.136
p-_lag1                       0.1025      0.019      5.298      0.000       0.065       0.140
p+_lag2                       0.0723      0.021      3.373      0.001       0.030       0.114
p-_lag2                       0.1187      0.020      5.838      0.000       0.079       0.159
p+_lag3                       0.0208      0.021      0.970      0.332      -0.021       0.063
p-_lag3                       0.0437      0.020      2.135      0.033       0.004       0.084
p+_lag4                       0.0372      0.022      1.727      0.084      -0.005       0.079
p-_lag4                       0.0023      0.021      0.112      0.911      -0.038       0.043
p+_lag5                       0.0114      0.022      0.529      0.597      -0.031       0.054
p-_lag5                      -0.0232      0.021     -1.123      0.262      -0.064       0.017
p+_lag6                       0.0267      0.021      1.262      0.207      -0.015       0.068
p-_lag6                      -0.0411      0.021     -1.991      0.047      -0.082      -0.001
p+_lag7                      -0.0087      0.021     -0.408      0.684      -0.051       0.033
p-_lag7                      -0.0288      0.021     -1.378      0.168      -0.070       0.012
p+_lag8                       0.0212      0.021      0.997      0.319      -0.021       0.063
p-_lag8                       0.0010      0.021      0.050      0.961      -0.040       0.042
p+_lag9                   -4.165e-05      0.021     -0.002      0.998      -0.042       0.042
p-_lag9                       0.0144      0.021      0.692      0.489      -0.026       0.055
p+_lag10                     -0.0097      0.021     -0.464      0.643      -0.051       0.032
p-_lag10                      0.0216      0.021      1.052      0.293      -0.019       0.062
p+_lag11                      0.0194      0.020      0.984      0.326      -0.019       0.058
p-_lag11                     -0.0469      0.021     -2.286      0.022      -0.087      -0.007
p+_lag12                      0.0084      0.019      0.438      0.662      -0.029       0.046
p-_lag12                     -0.0136      0.020     -0.673      0.501      -0.053       0.026
==============================================================================
Omnibus:                      225.737   Durbin-Watson:                   1.249
Prob(Omnibus):                  0.000   Jarque-Bera (JB):             2823.340
Skew:                           0.719   Prob(JB):                         0.00
Kurtosis:                      11.363   Cond. No.                         5.50
==============================================================================

Warnings:
[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.
                              OLS Regression Results                             
=================================================================================
Dep. Variable:     chg_Gasoline_price_US   R-squared:                       0.239
Model:                               OLS   Adj. R-squared:                  0.196
Method:                    Least Squares   F-statistic:                     5.523
Date:                   Sun, 28 Feb 2021   Prob (F-statistic):           8.89e-28
Time:                           15:24:56   Log-Likelihood:                 2401.2
No. Observations:                    929   AIC:                            -4702.
Df Residuals:                        879   BIC:                            -4461.
Df Model:                             50                                         
Covariance Type:               nonrobust                                         
=============================================================================================
                                coef    std err          t      P>|t|      [0.025      0.975]
---------------------------------------------------------------------------------------------
chg_oil_spot_WTI_Positive     0.0059      0.022      0.273      0.785      -0.037       0.049
chg_oil_spot_WTI_Negative     0.0772      0.019      4.092      0.000       0.040       0.114
p+_lag1                       0.0923      0.022      4.201      0.000       0.049       0.135
p-_lag1                       0.1023      0.020      5.198      0.000       0.064       0.141
p+_lag2                       0.0727      0.022      3.301      0.001       0.029       0.116
p-_lag2                       0.1208      0.021      5.837      0.000       0.080       0.161
p+_lag3                       0.0185      0.022      0.840      0.401      -0.025       0.062
p-_lag3                       0.0396      0.021      1.898      0.058      -0.001       0.081
p+_lag4                       0.0426      0.022      1.934      0.053      -0.001       0.086
p-_lag4                       0.0045      0.021      0.215      0.830      -0.037       0.046
p+_lag5                       0.0163      0.022      0.742      0.458      -0.027       0.059
p-_lag5                      -0.0285      0.021     -1.356      0.176      -0.070       0.013
p+_lag6                       0.0254      0.022      1.158      0.247      -0.018       0.069
p-_lag6                      -0.0374      0.021     -1.776      0.076      -0.079       0.004
p+_lag7                      -0.0060      0.022     -0.270      0.787      -0.049       0.038
p-_lag7                      -0.0297      0.021     -1.400      0.162      -0.071       0.012
p+_lag8                       0.0164      0.022      0.742      0.458      -0.027       0.060
p-_lag8                       0.0021      0.021      0.100      0.920      -0.040       0.044
p+_lag9                       0.0027      0.022      0.121      0.904      -0.041       0.046
p-_lag9                       0.0167      0.021      0.784      0.433      -0.025       0.058
p+_lag10                     -0.0205      0.022     -0.925      0.355      -0.064       0.023
p-_lag10                      0.0310      0.021      1.455      0.146      -0.011       0.073
p+_lag11                      0.0012      0.022      0.053      0.958      -0.042       0.045
p-_lag11                     -0.0414      0.021     -1.941      0.053      -0.083       0.000
p+_lag12                     -0.0119      0.022     -0.535      0.593      -0.055       0.032
p-_lag12                     -0.0042      0.021     -0.199      0.843      -0.046       0.038
p+_lag13                     -0.0322      0.022     -1.448      0.148      -0.076       0.011
p-_lag13                     -0.0124      0.021     -0.584      0.560      -0.054       0.029
p+_lag14                     -0.0116      0.022     -0.523      0.601      -0.055       0.032
p-_lag14                     -0.0034      0.021     -0.160      0.873      -0.045       0.038
p+_lag15                      0.0022      0.022      0.099      0.921      -0.041       0.046
p-_lag15                     -0.0565      0.021     -2.659      0.008      -0.098      -0.015
p+_lag16                     -0.0571      0.022     -2.570      0.010      -0.101      -0.013
p-_lag16                      0.0137      0.021      0.645      0.519      -0.028       0.055
p+_lag17                     -0.0129      0.022     -0.578      0.563      -0.056       0.031
p-_lag17                     -0.0357      0.021     -1.677      0.094      -0.078       0.006
p+_lag18                     -0.0013      0.022     -0.057      0.954      -0.044       0.042
p-_lag18                     -0.0359      0.021     -1.683      0.093      -0.078       0.006
p+_lag19                      0.0100      0.022      0.452      0.651      -0.033       0.053
p-_lag19                     -0.0094      0.021     -0.439      0.661      -0.051       0.033
p+_lag20                      0.0334      0.022      1.521      0.129      -0.010       0.077
p-_lag20                     -0.0025      0.021     -0.119      0.905      -0.044       0.039
p+_lag21                      0.0150      0.022      0.684      0.494      -0.028       0.058
p-_lag21                      0.0073      0.021      0.344      0.731      -0.034       0.049
p+_lag22                     -0.0030      0.022     -0.138      0.890      -0.046       0.040
p-_lag22                      0.0308      0.021      1.472      0.141      -0.010       0.072
p+_lag23                      0.0306      0.021      1.486      0.138      -0.010       0.071
p-_lag23                     -0.0045      0.021     -0.213      0.831      -0.046       0.037
p+_lag24                     -0.0084      0.020     -0.421      0.674      -0.048       0.031
p-_lag24                     -0.0065      0.021     -0.312      0.755      -0.048       0.035
==============================================================================
Omnibus:                      213.109   Durbin-Watson:                   1.246
Prob(Omnibus):                  0.000   Jarque-Bera (JB):             2909.743
Skew:                           0.637   Prob(JB):                         0.00
Kurtosis:                      11.576   Cond. No.                         7.48
==============================================================================

Warnings:
[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.
In [162]:
# test perfect number of lags used in model
import statsmodels.api as sm

nlag = 2
analysis = oil_co2_df.copy()
for i in [2]: #range(nlag+1):
    #print(i)
#    analysis = oil_co2_df.copy()
    analysis = analysis[['chg_oil_spot_WTI_Positive','chg_oil_spot_WTI_Negative','chg_Gasoline_price_US','chg_co2_conc']].dropna(subset = ['chg_co2_conc'])
    analysis_reg = analysis.copy()
    #running = i.copy()
    column_names = ['chg_oil_spot_WTI_Positive','chg_oil_spot_WTI_Negative']
    print("Number of lag : ", str(i))
    while i > 0:
        text1 = 'chg_oil_spot_WTI_Positive' + '_lag' + '_' + str(i)
        analysis_reg[text1] = oil_co2_df['chg_oil_spot_WTI_Positive'].shift(i)
        column_names.append(text1)
        
        text2 = 'chg_oil_spot_WTI_Negative' + '_lag' + '_' + str(i)
        analysis_reg[text2] = oil_co2_df['chg_oil_spot_WTI_Negative'].shift(i)
        column_names.append(text2)
        
        i = i - 1
        #print(i+1)
    #print(" ")
    analysis_reg = analysis_reg.dropna(subset = column_names)
    
    x = analysis_reg[column_names][1:][['chg_oil_spot_WTI_Positive','chg_oil_spot_WTI_Negative','chg_oil_spot_WTI_Positive_lag_1','chg_oil_spot_WTI_Negative_lag_1','chg_oil_spot_WTI_Positive_lag_2','chg_oil_spot_WTI_Negative_lag_2']]
    reg_model = sm.OLS(analysis_reg['chg_Gasoline_price_US'][1:],x)
    result = reg_model.fit()
    print("Adj. R-squared : ", result.rsquared_adj)
    print("P-value : ")
    print(result.summary())
    #print(result.pvalues)
    print(" ")
Number of lag :  2
Adj. R-squared :  0.2898402045584916
P-value : 
                              OLS Regression Results                             
=================================================================================
Dep. Variable:     chg_Gasoline_price_US   R-squared:                       0.294
Model:                               OLS   Adj. R-squared:                  0.290
Method:                    Least Squares   F-statistic:                     65.69
Date:                   Sun, 28 Feb 2021   Prob (F-statistic):           2.88e-68
Time:                           15:24:56   Log-Likelihood:                 2500.8
No. Observations:                    951   AIC:                            -4990.
Df Residuals:                        945   BIC:                            -4960.
Df Model:                              6                                         
Covariance Type:               nonrobust                                         
===================================================================================================
                                      coef    std err          t      P>|t|      [0.025      0.975]
---------------------------------------------------------------------------------------------------
chg_oil_spot_WTI_Positive           0.0531      0.019      2.850      0.004       0.017       0.090
chg_oil_spot_WTI_Negative           0.0283      0.017      1.623      0.105      -0.006       0.062
chg_oil_spot_WTI_Positive_lag_1     0.1423      0.017      8.182      0.000       0.108       0.176
chg_oil_spot_WTI_Negative_lag_1     0.1101      0.017      6.396      0.000       0.076       0.144
chg_oil_spot_WTI_Positive_lag_2     0.1157      0.017      6.846      0.000       0.083       0.149
chg_oil_spot_WTI_Negative_lag_2     0.1599      0.018      8.825      0.000       0.124       0.195
==============================================================================
Omnibus:                      264.625   Durbin-Watson:                   1.338
Prob(Omnibus):                  0.000   Jarque-Bera (JB):             3754.722
Skew:                           0.861   Prob(JB):                         0.00
Kurtosis:                      12.581   Cond. No.                         2.90
==============================================================================

Warnings:
[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.
 
In [163]:
### Weekly CO2 ###
### Weekly Lag 0###

analysis = oil_co2_df.copy()

analysis = analysis[['chg_oil_spot_WTI_Positive','chg_oil_spot_WTI_Negative','chg_Gasoline_price_US','chg_co2_conc']].dropna(subset = ['chg_co2_conc'])
analysis_reg = analysis.copy()


analysis_reg = analysis_reg

x = analysis_reg[['chg_oil_spot_WTI_Positive', 'chg_oil_spot_WTI_Negative']] 

reg_model = sm.OLS(analysis_reg['chg_co2_conc'],x)
result = reg_model.fit()
print(result.summary())

### Weekly ###
### Weekly Lag 3###

analysis = oil_co2_df.copy()

analysis = analysis[['chg_oil_spot_WTI_Positive','chg_oil_spot_WTI_Negative','chg_Gasoline_price_US','chg_co2_conc']].dropna(subset = ['chg_co2_conc'])
analysis_reg = analysis.copy()


analysis_reg['p+_lag1'] = analysis['chg_oil_spot_WTI_Positive'].shift(1)
analysis_reg['p+_lag2'] = analysis['chg_oil_spot_WTI_Positive'].shift(2)
analysis_reg['p+_lag3'] = analysis['chg_oil_spot_WTI_Positive'].shift(3)


analysis_reg['p-_lag1'] = analysis['chg_oil_spot_WTI_Negative'].shift(1)
analysis_reg['p-_lag2'] = analysis['chg_oil_spot_WTI_Negative'].shift(2)
analysis_reg['p-_lag3'] = analysis['chg_oil_spot_WTI_Negative'].shift(3)



analysis_reg = analysis_reg.dropna(subset = ['p+_lag1','p-_lag1','p+_lag2','p-_lag2','p+_lag3','p-_lag3'])

x = analysis_reg[['chg_oil_spot_WTI_Positive', 'chg_oil_spot_WTI_Negative','p+_lag1','p-_lag1','p+_lag2','p-_lag2','p+_lag3','p-_lag3']] 

reg_model = sm.OLS(analysis_reg['chg_co2_conc'],x)
result = reg_model.fit()
print(result.summary())


### Weekly ###
### Weekly Lag 6###

analysis = oil_co2_df.copy()

analysis = analysis[['chg_oil_spot_WTI_Positive','chg_oil_spot_WTI_Negative','chg_Gasoline_price_US','chg_co2_conc']].dropna(subset = ['chg_co2_conc'])
analysis_reg = analysis.copy()


analysis_reg['p+_lag1'] = analysis['chg_oil_spot_WTI_Positive'].shift(1)
analysis_reg['p+_lag2'] = analysis['chg_oil_spot_WTI_Positive'].shift(2)
analysis_reg['p+_lag3'] = analysis['chg_oil_spot_WTI_Positive'].shift(3)
analysis_reg['p+_lag4'] = analysis['chg_oil_spot_WTI_Positive'].shift(4)
analysis_reg['p+_lag5'] = analysis['chg_oil_spot_WTI_Positive'].shift(5)
analysis_reg['p+_lag6'] = analysis['chg_oil_spot_WTI_Positive'].shift(6)

analysis_reg['p-_lag1'] = analysis['chg_oil_spot_WTI_Negative'].shift(1)
analysis_reg['p-_lag2'] = analysis['chg_oil_spot_WTI_Negative'].shift(2)
analysis_reg['p-_lag3'] = analysis['chg_oil_spot_WTI_Negative'].shift(3)
analysis_reg['p-_lag4'] = analysis['chg_oil_spot_WTI_Negative'].shift(4)
analysis_reg['p-_lag5'] = analysis['chg_oil_spot_WTI_Negative'].shift(5)
analysis_reg['p-_lag6'] = analysis['chg_oil_spot_WTI_Negative'].shift(6)


analysis_reg = analysis_reg.dropna(subset = ['p+_lag1','p-_lag1','p+_lag2','p-_lag2','p+_lag3','p-_lag3','p+_lag4','p-_lag4','p+_lag5','p-_lag5','p+_lag6','p-_lag6'])

x = analysis_reg[['chg_oil_spot_WTI_Positive', 'chg_oil_spot_WTI_Negative','p+_lag1','p-_lag1','p+_lag2','p-_lag2','p+_lag3','p-_lag3','p+_lag4','p-_lag4','p+_lag5','p-_lag5','p+_lag6','p-_lag6']] 

reg_model = sm.OLS(analysis_reg['chg_co2_conc'],x)
result = reg_model.fit()
print(result.summary())


### Weekly ###
### Weekly Lag 12###

analysis = oil_co2_df.copy()

analysis = analysis[['chg_oil_spot_WTI_Positive','chg_oil_spot_WTI_Negative','chg_Gasoline_price_US','chg_co2_conc']].dropna(subset = ['chg_co2_conc'])
analysis_reg = analysis.copy()

analysis_reg['p+_lag1'] = analysis['chg_oil_spot_WTI_Positive'].shift(1)
analysis_reg['p+_lag2'] = analysis['chg_oil_spot_WTI_Positive'].shift(2)
analysis_reg['p+_lag3'] = analysis['chg_oil_spot_WTI_Positive'].shift(3)
analysis_reg['p+_lag4'] = analysis['chg_oil_spot_WTI_Positive'].shift(4)
analysis_reg['p+_lag5'] = analysis['chg_oil_spot_WTI_Positive'].shift(5)
analysis_reg['p+_lag6'] = analysis['chg_oil_spot_WTI_Positive'].shift(6)
analysis_reg['p+_lag7'] = analysis['chg_oil_spot_WTI_Positive'].shift(7)
analysis_reg['p+_lag8'] = analysis['chg_oil_spot_WTI_Positive'].shift(8)
analysis_reg['p+_lag9'] = analysis['chg_oil_spot_WTI_Positive'].shift(9)
analysis_reg['p+_lag10'] = analysis['chg_oil_spot_WTI_Positive'].shift(10)
analysis_reg['p+_lag11'] = analysis['chg_oil_spot_WTI_Positive'].shift(11)
analysis_reg['p+_lag12'] = analysis['chg_oil_spot_WTI_Positive'].shift(12)

analysis_reg['p-_lag1'] = analysis['chg_oil_spot_WTI_Negative'].shift(1)
analysis_reg['p-_lag2'] = analysis['chg_oil_spot_WTI_Negative'].shift(2)
analysis_reg['p-_lag3'] = analysis['chg_oil_spot_WTI_Negative'].shift(3)
analysis_reg['p-_lag4'] = analysis['chg_oil_spot_WTI_Negative'].shift(4)
analysis_reg['p-_lag5'] = analysis['chg_oil_spot_WTI_Negative'].shift(5)
analysis_reg['p-_lag6'] = analysis['chg_oil_spot_WTI_Negative'].shift(6)
analysis_reg['p-_lag7'] = analysis['chg_oil_spot_WTI_Negative'].shift(7)
analysis_reg['p-_lag8'] = analysis['chg_oil_spot_WTI_Negative'].shift(8)
analysis_reg['p-_lag9'] = analysis['chg_oil_spot_WTI_Negative'].shift(9)
analysis_reg['p-_lag10'] = analysis['chg_oil_spot_WTI_Negative'].shift(10)
analysis_reg['p-_lag11'] = analysis['chg_oil_spot_WTI_Negative'].shift(11)
analysis_reg['p-_lag12'] = analysis['chg_oil_spot_WTI_Negative'].shift(12)


analysis_reg = analysis_reg.dropna(subset = ['p+_lag1','p-_lag1','p+_lag2','p-_lag2','p+_lag3','p-_lag3','p+_lag4','p-_lag4','p+_lag5','p-_lag5','p+_lag6','p-_lag6','p+_lag7','p-_lag7','p+_lag8','p-_lag8','p+_lag9','p-_lag9','p+_lag10','p-_lag10','p+_lag11','p-_lag11','p+_lag12','p-_lag12'])

x = analysis_reg[['chg_oil_spot_WTI_Positive', 'chg_oil_spot_WTI_Negative','p+_lag1','p-_lag1','p+_lag2','p-_lag2','p+_lag3','p-_lag3','p+_lag4','p-_lag4','p+_lag5','p-_lag5','p+_lag6','p-_lag6','p+_lag7','p-_lag7','p+_lag8','p-_lag8','p+_lag9','p-_lag9','p+_lag10','p-_lag10','p+_lag11','p-_lag11','p+_lag12','p-_lag12']] 

reg_model = sm.OLS(analysis_reg['chg_co2_conc'],x)
result = reg_model.fit()
print(result.summary())


### Weekly ###
### Weekly Lag 24###

analysis = oil_co2_df.copy()

analysis = analysis[['chg_oil_spot_WTI_Positive','chg_oil_spot_WTI_Negative','chg_Gasoline_price_US','chg_co2_conc']].dropna(subset = ['chg_co2_conc'])
analysis_reg = analysis.copy()

analysis_reg['p+_lag1'] = analysis['chg_oil_spot_WTI_Positive'].shift(1)
analysis_reg['p+_lag2'] = analysis['chg_oil_spot_WTI_Positive'].shift(2)
analysis_reg['p+_lag3'] = analysis['chg_oil_spot_WTI_Positive'].shift(3)
analysis_reg['p+_lag4'] = analysis['chg_oil_spot_WTI_Positive'].shift(4)
analysis_reg['p+_lag5'] = analysis['chg_oil_spot_WTI_Positive'].shift(5)
analysis_reg['p+_lag6'] = analysis['chg_oil_spot_WTI_Positive'].shift(6)
analysis_reg['p+_lag7'] = analysis['chg_oil_spot_WTI_Positive'].shift(7)
analysis_reg['p+_lag8'] = analysis['chg_oil_spot_WTI_Positive'].shift(8)
analysis_reg['p+_lag9'] = analysis['chg_oil_spot_WTI_Positive'].shift(9)
analysis_reg['p+_lag10'] = analysis['chg_oil_spot_WTI_Positive'].shift(10)
analysis_reg['p+_lag11'] = analysis['chg_oil_spot_WTI_Positive'].shift(11)
analysis_reg['p+_lag12'] = analysis['chg_oil_spot_WTI_Positive'].shift(12)
analysis_reg['p+_lag13'] = analysis['chg_oil_spot_WTI_Positive'].shift(13)
analysis_reg['p+_lag14'] = analysis['chg_oil_spot_WTI_Positive'].shift(14)
analysis_reg['p+_lag15'] = analysis['chg_oil_spot_WTI_Positive'].shift(15)
analysis_reg['p+_lag16'] = analysis['chg_oil_spot_WTI_Positive'].shift(16)
analysis_reg['p+_lag17'] = analysis['chg_oil_spot_WTI_Positive'].shift(17)
analysis_reg['p+_lag18'] = analysis['chg_oil_spot_WTI_Positive'].shift(18)
analysis_reg['p+_lag19'] = analysis['chg_oil_spot_WTI_Positive'].shift(19)
analysis_reg['p+_lag20'] = analysis['chg_oil_spot_WTI_Positive'].shift(20)
analysis_reg['p+_lag21'] = analysis['chg_oil_spot_WTI_Positive'].shift(21)
analysis_reg['p+_lag22'] = analysis['chg_oil_spot_WTI_Positive'].shift(22)
analysis_reg['p+_lag23'] = analysis['chg_oil_spot_WTI_Positive'].shift(23)
analysis_reg['p+_lag24'] = analysis['chg_oil_spot_WTI_Positive'].shift(24)

analysis_reg['p-_lag1'] = analysis['chg_oil_spot_WTI_Negative'].shift(1)
analysis_reg['p-_lag2'] = analysis['chg_oil_spot_WTI_Negative'].shift(2)
analysis_reg['p-_lag3'] = analysis['chg_oil_spot_WTI_Negative'].shift(3)
analysis_reg['p-_lag4'] = analysis['chg_oil_spot_WTI_Negative'].shift(4)
analysis_reg['p-_lag5'] = analysis['chg_oil_spot_WTI_Negative'].shift(5)
analysis_reg['p-_lag6'] = analysis['chg_oil_spot_WTI_Negative'].shift(6)
analysis_reg['p-_lag7'] = analysis['chg_oil_spot_WTI_Negative'].shift(7)
analysis_reg['p-_lag8'] = analysis['chg_oil_spot_WTI_Negative'].shift(8)
analysis_reg['p-_lag9'] = analysis['chg_oil_spot_WTI_Negative'].shift(9)
analysis_reg['p-_lag10'] = analysis['chg_oil_spot_WTI_Negative'].shift(10)
analysis_reg['p-_lag11'] = analysis['chg_oil_spot_WTI_Negative'].shift(11)
analysis_reg['p-_lag12'] = analysis['chg_oil_spot_WTI_Negative'].shift(12)
analysis_reg['p-_lag13'] = analysis['chg_oil_spot_WTI_Negative'].shift(13)
analysis_reg['p-_lag14'] = analysis['chg_oil_spot_WTI_Negative'].shift(14)
analysis_reg['p-_lag15'] = analysis['chg_oil_spot_WTI_Negative'].shift(15)
analysis_reg['p-_lag16'] = analysis['chg_oil_spot_WTI_Negative'].shift(16)
analysis_reg['p-_lag17'] = analysis['chg_oil_spot_WTI_Negative'].shift(17)
analysis_reg['p-_lag18'] = analysis['chg_oil_spot_WTI_Negative'].shift(18)
analysis_reg['p-_lag19'] = analysis['chg_oil_spot_WTI_Negative'].shift(19)
analysis_reg['p-_lag20'] = analysis['chg_oil_spot_WTI_Negative'].shift(20)
analysis_reg['p-_lag21'] = analysis['chg_oil_spot_WTI_Negative'].shift(21)
analysis_reg['p-_lag22'] = analysis['chg_oil_spot_WTI_Negative'].shift(22)
analysis_reg['p-_lag23'] = analysis['chg_oil_spot_WTI_Negative'].shift(23)
analysis_reg['p-_lag24'] = analysis['chg_oil_spot_WTI_Negative'].shift(24)


analysis_reg = analysis_reg.dropna(subset = ['p+_lag1','p-_lag1','p+_lag2','p-_lag2','p+_lag3','p-_lag3','p+_lag4','p-_lag4','p+_lag5','p-_lag5','p+_lag6','p-_lag6','p+_lag7','p-_lag7','p+_lag8','p-_lag8','p+_lag9','p-_lag9','p+_lag10','p-_lag10','p+_lag11','p-_lag11','p+_lag12','p-_lag12'
                                             ,'p+_lag13','p-_lag13','p+_lag14','p-_lag14','p+_lag15','p-_lag15','p+_lag16','p-_lag16','p+_lag17','p-_lag17','p+_lag18','p-_lag18','p+_lag19','p-_lag19','p+_lag20','p-_lag20','p+_lag21','p-_lag21','p+_lag22','p-_lag22','p+_lag23','p-_lag23','p+_lag24','p-_lag24'])

x = analysis_reg[['chg_oil_spot_WTI_Positive', 'chg_oil_spot_WTI_Negative','p+_lag1','p-_lag1','p+_lag2','p-_lag2','p+_lag3','p-_lag3','p+_lag4','p-_lag4','p+_lag5','p-_lag5','p+_lag6','p-_lag6','p+_lag7','p-_lag7','p+_lag8','p-_lag8','p+_lag9','p-_lag9','p+_lag10','p-_lag10','p+_lag11','p-_lag11','p+_lag12','p-_lag12'
                                             ,'p+_lag13','p-_lag13','p+_lag14','p-_lag14','p+_lag15','p-_lag15','p+_lag16','p-_lag16','p+_lag17','p-_lag17','p+_lag18','p-_lag18','p+_lag19','p-_lag19','p+_lag20','p-_lag20','p+_lag21','p-_lag21','p+_lag22','p-_lag22','p+_lag23','p-_lag23','p+_lag24','p-_lag24']] 

reg_model = sm.OLS(analysis_reg['chg_co2_conc'],x)
result = reg_model.fit()
print(result.summary())
                            OLS Regression Results                            
==============================================================================
Dep. Variable:           chg_co2_conc   R-squared:                       0.014
Model:                            OLS   Adj. R-squared:                  0.012
Method:                 Least Squares   F-statistic:                     6.759
Date:                Sun, 28 Feb 2021   Prob (F-statistic):            0.00122
Time:                        15:24:57   Log-Likelihood:                 4835.8
No. Observations:                 953   AIC:                            -9668.
Df Residuals:                     951   BIC:                            -9658.
Df Model:                           2                                         
Covariance Type:            nonrobust                                         
=============================================================================================
                                coef    std err          t      P>|t|      [0.025      0.975]
---------------------------------------------------------------------------------------------
chg_oil_spot_WTI_Positive    -0.0020      0.001     -1.615      0.107      -0.004       0.000
chg_oil_spot_WTI_Negative     0.0038      0.001      3.303      0.001       0.002       0.006
==============================================================================
Omnibus:                        9.830   Durbin-Watson:                   1.946
Prob(Omnibus):                  0.007   Jarque-Bera (JB):               13.187
Skew:                           0.102   Prob(JB):                      0.00137
Kurtosis:                       3.539   Cond. No.                         1.06
==============================================================================

Warnings:
[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.
                            OLS Regression Results                            
==============================================================================
Dep. Variable:           chg_co2_conc   R-squared:                       0.026
Model:                            OLS   Adj. R-squared:                  0.017
Method:                 Least Squares   F-statistic:                     3.086
Date:                Sun, 28 Feb 2021   Prob (F-statistic):            0.00193
Time:                        15:24:57   Log-Likelihood:                 4826.8
No. Observations:                 950   AIC:                            -9638.
Df Residuals:                     942   BIC:                            -9599.
Df Model:                           8                                         
Covariance Type:            nonrobust                                         
=============================================================================================
                                coef    std err          t      P>|t|      [0.025      0.975]
---------------------------------------------------------------------------------------------
chg_oil_spot_WTI_Positive    -0.0001      0.002     -0.080      0.936      -0.003       0.003
chg_oil_spot_WTI_Negative     0.0030      0.001      2.050      0.041       0.000       0.006
p+_lag1                   -2.592e-05      0.002     -0.016      0.987      -0.003       0.003
p-_lag1                       0.0021      0.002      1.387      0.166      -0.001       0.005
p+_lag2                       0.0019      0.002      1.281      0.200      -0.001       0.005
p-_lag2                       0.0026      0.002      1.649      0.099      -0.000       0.006
p+_lag3                       0.0007      0.001      0.486      0.627      -0.002       0.004
p-_lag3                       0.0008      0.002      0.512      0.609      -0.002       0.004
==============================================================================
Omnibus:                        9.829   Durbin-Watson:                   1.941
Prob(Omnibus):                  0.007   Jarque-Bera (JB):               13.771
Skew:                           0.079   Prob(JB):                      0.00102
Kurtosis:                       3.568   Cond. No.                         3.07
==============================================================================

Warnings:
[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.
                            OLS Regression Results                            
==============================================================================
Dep. Variable:           chg_co2_conc   R-squared:                       0.026
Model:                            OLS   Adj. R-squared:                  0.011
Method:                 Least Squares   F-statistic:                     1.768
Date:                Sun, 28 Feb 2021   Prob (F-statistic):             0.0388
Time:                        15:24:57   Log-Likelihood:                 4814.2
No. Observations:                 947   AIC:                            -9600.
Df Residuals:                     933   BIC:                            -9533.
Df Model:                          14                                         
Covariance Type:            nonrobust                                         
=============================================================================================
                                coef    std err          t      P>|t|      [0.025      0.975]
---------------------------------------------------------------------------------------------
chg_oil_spot_WTI_Positive     0.0003      0.002      0.171      0.864      -0.003       0.004
chg_oil_spot_WTI_Negative     0.0028      0.001      1.908      0.057   -8.09e-05       0.006
p+_lag1                       0.0004      0.002      0.232      0.817      -0.003       0.004
p-_lag1                       0.0016      0.002      1.013      0.311      -0.001       0.005
p+_lag2                       0.0020      0.002      1.214      0.225      -0.001       0.005
p-_lag2                       0.0024      0.002      1.455      0.146      -0.001       0.006
p+_lag3                       0.0009      0.002      0.567      0.571      -0.002       0.004
p-_lag3                       0.0009      0.002      0.570      0.569      -0.002       0.004
p+_lag4                      -0.0018      0.002     -1.107      0.269      -0.005       0.001
p-_lag4                       0.0006      0.002      0.382      0.703      -0.003       0.004
p+_lag5                       0.0007      0.002      0.475      0.635      -0.002       0.004
p-_lag5                       0.0004      0.002      0.270      0.787      -0.003       0.004
p+_lag6                       0.0003      0.002      0.188      0.851      -0.003       0.003
p-_lag6                    6.385e-05      0.002      0.040      0.968      -0.003       0.003
==============================================================================
Omnibus:                       10.864   Durbin-Watson:                   1.946
Prob(Omnibus):                  0.004   Jarque-Bera (JB):               15.361
Skew:                           0.095   Prob(JB):                     0.000462
Kurtosis:                       3.594   Cond. No.                         4.02
==============================================================================

Warnings:
[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.
                            OLS Regression Results                            
==============================================================================
Dep. Variable:           chg_co2_conc   R-squared:                       0.033
Model:                            OLS   Adj. R-squared:                  0.006
Method:                 Least Squares   F-statistic:                     1.207
Date:                Sun, 28 Feb 2021   Prob (F-statistic):              0.219
Time:                        15:24:57   Log-Likelihood:                 4787.5
No. Observations:                 941   AIC:                            -9523.
Df Residuals:                     915   BIC:                            -9397.
Df Model:                          26                                         
Covariance Type:            nonrobust                                         
=============================================================================================
                                coef    std err          t      P>|t|      [0.025      0.975]
---------------------------------------------------------------------------------------------
chg_oil_spot_WTI_Positive     0.0002      0.002      0.127      0.899      -0.003       0.004
chg_oil_spot_WTI_Negative     0.0031      0.001      2.082      0.038       0.000       0.006
p+_lag1                       0.0002      0.002      0.136      0.892      -0.003       0.004
p-_lag1                       0.0017      0.002      1.084      0.279      -0.001       0.005
p+_lag2                       0.0018      0.002      1.045      0.296      -0.002       0.005
p-_lag2                       0.0026      0.002      1.572      0.116      -0.001       0.006
p+_lag3                       0.0002      0.002      0.097      0.923      -0.003       0.004
p-_lag3                       0.0009      0.002      0.549      0.583      -0.002       0.004
p+_lag4                      -0.0024      0.002     -1.351      0.177      -0.006       0.001
p-_lag4                       0.0006      0.002      0.351      0.726      -0.003       0.004
p+_lag5                    4.528e-05      0.002      0.026      0.979      -0.003       0.003
p-_lag5                      -0.0002      0.002     -0.108      0.914      -0.003       0.003
p+_lag6                      -0.0006      0.002     -0.353      0.724      -0.004       0.003
p-_lag6                       0.0006      0.002      0.354      0.724      -0.003       0.004
p+_lag7                      -0.0004      0.002     -0.247      0.805      -0.004       0.003
p-_lag7                       0.0002      0.002      0.135      0.893      -0.003       0.004
p+_lag8                       0.0005      0.002      0.314      0.754      -0.003       0.004
p-_lag8                   -4.893e-05      0.002     -0.029      0.977      -0.003       0.003
p+_lag9                      -0.0018      0.002     -1.052      0.293      -0.005       0.002
p-_lag9                       0.0003      0.002      0.197      0.844      -0.003       0.004
p+_lag10                      0.0019      0.002      1.132      0.258      -0.001       0.005
p-_lag10                     -0.0008      0.002     -0.478      0.632      -0.004       0.002
p+_lag11                      0.0003      0.002      0.191      0.849      -0.003       0.003
p-_lag11                     -0.0012      0.002     -0.719      0.472      -0.004       0.002
p+_lag12                      0.0014      0.002      0.932      0.351      -0.002       0.004
p-_lag12                     -0.0017      0.002     -1.058      0.291      -0.005       0.001
==============================================================================
Omnibus:                       11.696   Durbin-Watson:                   1.949
Prob(Omnibus):                  0.003   Jarque-Bera (JB):               16.766
Skew:                           0.104   Prob(JB):                     0.000229
Kurtosis:                       3.620   Cond. No.                         5.50
==============================================================================

Warnings:
[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.
                            OLS Regression Results                            
==============================================================================
Dep. Variable:           chg_co2_conc   R-squared:                       0.047
Model:                            OLS   Adj. R-squared:                 -0.007
Method:                 Least Squares   F-statistic:                    0.8725
Date:                Sun, 28 Feb 2021   Prob (F-statistic):              0.722
Time:                        15:24:57   Log-Likelihood:                 4735.2
No. Observations:                 929   AIC:                            -9370.
Df Residuals:                     879   BIC:                            -9129.
Df Model:                          50                                         
Covariance Type:            nonrobust                                         
=============================================================================================
                                coef    std err          t      P>|t|      [0.025      0.975]
---------------------------------------------------------------------------------------------
chg_oil_spot_WTI_Positive  4.688e-05      0.002      0.027      0.979      -0.003       0.004
chg_oil_spot_WTI_Negative     0.0032      0.002      2.105      0.036       0.000       0.006
p+_lag1                   -6.772e-05      0.002     -0.038      0.970      -0.004       0.003
p-_lag1                       0.0018      0.002      1.100      0.272      -0.001       0.005
p+_lag2                       0.0021      0.002      1.178      0.239      -0.001       0.006
p-_lag2                       0.0023      0.002      1.360      0.174      -0.001       0.006
p+_lag3                       0.0004      0.002      0.215      0.830      -0.003       0.004
p-_lag3                       0.0008      0.002      0.496      0.620      -0.002       0.004
p+_lag4                      -0.0021      0.002     -1.195      0.233      -0.006       0.001
p-_lag4                       0.0006      0.002      0.360      0.719      -0.003       0.004
p+_lag5                   -2.836e-05      0.002     -0.016      0.987      -0.004       0.003
p-_lag5                      -0.0001      0.002     -0.069      0.945      -0.003       0.003
p+_lag6                      -0.0011      0.002     -0.608      0.543      -0.005       0.002
p-_lag6                       0.0007      0.002      0.431      0.666      -0.003       0.004
p+_lag7                      -0.0008      0.002     -0.452      0.651      -0.004       0.003
p-_lag7                       0.0003      0.002      0.184      0.854      -0.003       0.004
p+_lag8                       0.0009      0.002      0.503      0.615      -0.003       0.004
p-_lag8                      -0.0003      0.002     -0.196      0.845      -0.004       0.003
p+_lag9                      -0.0023      0.002     -1.280      0.201      -0.006       0.001
p-_lag9                       0.0003      0.002      0.166      0.868      -0.003       0.004
p+_lag10                      0.0021      0.002      1.169      0.243      -0.001       0.006
p-_lag10                     -0.0008      0.002     -0.460      0.646      -0.004       0.003
p+_lag11                      0.0004      0.002      0.220      0.826      -0.003       0.004
p-_lag11                     -0.0013      0.002     -0.752      0.452      -0.005       0.002
p+_lag12                      0.0012      0.002      0.665      0.506      -0.002       0.005
p-_lag12                     -0.0020      0.002     -1.172      0.242      -0.005       0.001
p+_lag13                      0.0011      0.002      0.612      0.541      -0.002       0.005
p-_lag13                     -0.0003      0.002     -0.158      0.874      -0.004       0.003
p+_lag14                      0.0013      0.002      0.722      0.471      -0.002       0.005
p-_lag14                     -0.0007      0.002     -0.400      0.689      -0.004       0.003
p+_lag15                      0.0015      0.002      0.829      0.407      -0.002       0.005
p-_lag15                      0.0018      0.002      1.025      0.305      -0.002       0.005
p+_lag16                      0.0009      0.002      0.505      0.614      -0.003       0.004
p-_lag16                     -0.0013      0.002     -0.729      0.466      -0.005       0.002
p+_lag17                      0.0003      0.002      0.162      0.871      -0.003       0.004
p-_lag17                      0.0020      0.002      1.140      0.255      -0.001       0.005
p+_lag18                      0.0005      0.002      0.254      0.800      -0.003       0.004
p-_lag18                      0.0011      0.002      0.659      0.510      -0.002       0.005
p+_lag19                     -0.0005      0.002     -0.290      0.772      -0.004       0.003
p-_lag19                     -0.0004      0.002     -0.260      0.795      -0.004       0.003
p+_lag20                     -0.0017      0.002     -0.949      0.343      -0.005       0.002
p-_lag20                      0.0019      0.002      1.112      0.266      -0.001       0.005
p+_lag21                      0.0024      0.002      1.340      0.181      -0.001       0.006
p-_lag21                     -0.0005      0.002     -0.283      0.778      -0.004       0.003
p+_lag22                     -0.0005      0.002     -0.311      0.756      -0.004       0.003
p-_lag22                     -0.0004      0.002     -0.231      0.818      -0.004       0.003
p+_lag23                     -0.0006      0.002     -0.340      0.734      -0.004       0.003
p-_lag23                      0.0005      0.002      0.275      0.783      -0.003       0.004
p+_lag24                     -0.0020      0.002     -1.231      0.219      -0.005       0.001
p-_lag24                     -0.0008      0.002     -0.465      0.642      -0.004       0.003
==============================================================================
Omnibus:                       13.581   Durbin-Watson:                   1.951
Prob(Omnibus):                  0.001   Jarque-Bera (JB):               20.945
Skew:                           0.099   Prob(JB):                     2.83e-05
Kurtosis:                       3.708   Cond. No.                         7.48
==============================================================================

Warnings:
[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.
Monthly
In [164]:
#Monthly
analysis = oil_co2_df.copy()
oil_co2_df.columns
Out[164]:
Index(['Weekindex', 'Date', 'Year', 'Month', 'Week', 'Day', 'Par_Month',
       'Par_Day', 'oil_spot_WTI', 'oil_spot_Brent', 'future_oil_contract_1',
       'sugar_price_us', 'ethanol_price_us', 'chg_oil_spot_WTI',
       'chg_oil_spot_Brent', 'chg_oil_spot_WTI_Positive',
       'chg_oil_spot_WTI_Negative', 'chg_oil_future_contract1',
       'chg_oil_future_contract1_Positive',
       'chg_oil_future_contract1_Negative', 'Gasoline_Price_US',
       'chg_Gasoline_price_US', 'chg_Gasoline_price_US_Positive',
       'chg_Gasoline_price_US_future', 'Date_edited', 'year', 'month', 'day',
       'decimal', 'average', 'ndays', '1_year_ago', '10_years_ago',
       'increase_since_1800', 'co2_conc', 'chg_co2_conc'],
      dtype='object')
In [165]:
analysis_month = analysis.groupby('Par_Month').last()[['oil_spot_WTI','Gasoline_Price_US','co2_conc']]
In [166]:
analysis_reg_month = np.log(analysis_month) - np.log(analysis_month.shift(1))
analysis_reg_month.dropna(inplace = True)
analysis_reg_month['co2_conc'] = analysis_reg_month['co2_conc'] - analysis_reg_month['co2_conc'].shift(12)
analysis_reg_month.dropna(inplace = True)
In [167]:
analysis_reg_month
Out[167]:
oil_spot_WTI Gasoline_Price_US co2_conc
Par_Month
199203 0.026401 0.000986 -0.005353
199204 0.043840 0.041492 0.001256
199205 0.098705 0.056948 0.004616
199206 0.013019 0.029039 -0.000425
199207 -0.026668 -0.021921 -0.003936
... ... ... ...
202008 0.068893 0.002395 -0.002439
202009 -0.069891 -0.005758 0.002333
202010 -0.116910 -0.012104 -0.002234
202011 0.219771 -0.021665 0.002038
202012 0.085227 0.071545 -0.001917

346 rows × 3 columns

In [168]:
### Month ###
analysis_reg_month_edited = analysis_reg_month.copy()

analysis_reg_month_edited['positive_change'] = list(map(lambda x : 0 if x <= 0 else x,analysis_reg_month['oil_spot_WTI'] ))
analysis_reg_month_edited['negative_change'] = list(map(lambda x : 0 if x >= 0 else x,analysis_reg_month['oil_spot_WTI'] ))


analysis_reg_month_edited['p+_lag1'] = analysis_reg_month_edited['positive_change'].shift(1)
analysis_reg_month_edited['p+_lag2'] = analysis_reg_month_edited['positive_change'].shift(2)
analysis_reg_month_edited['p+_lag3'] = analysis_reg_month_edited['positive_change'].shift(3)
analysis_reg_month_edited['p+_lag4'] = analysis_reg_month_edited['positive_change'].shift(4)
analysis_reg_month_edited['p+_lag5'] = analysis_reg_month_edited['positive_change'].shift(5)
analysis_reg_month_edited['p+_lag6'] = analysis_reg_month_edited['positive_change'].shift(6)
analysis_reg_month_edited['p+_lag7'] = analysis_reg_month_edited['positive_change'].shift(7)
analysis_reg_month_edited['p+_lag8'] = analysis_reg_month_edited['positive_change'].shift(8)
analysis_reg_month_edited['p+_lag9'] = analysis_reg_month_edited['positive_change'].shift(9)
analysis_reg_month_edited['p+_lag10'] = analysis_reg_month_edited['positive_change'].shift(10)

analysis_reg_month_edited['p-_lag1'] = analysis_reg_month_edited['negative_change'].shift(1)
analysis_reg_month_edited['p-_lag2'] = analysis_reg_month_edited['negative_change'].shift(2)
analysis_reg_month_edited['p-_lag3'] = analysis_reg_month_edited['negative_change'].shift(3)
analysis_reg_month_edited['p-_lag4'] = analysis_reg_month_edited['negative_change'].shift(4)
analysis_reg_month_edited['p-_lag5'] = analysis_reg_month_edited['negative_change'].shift(5)
analysis_reg_month_edited['p-_lag6'] = analysis_reg_month_edited['negative_change'].shift(6)
analysis_reg_month_edited['p-_lag7'] = analysis_reg_month_edited['negative_change'].shift(7)
analysis_reg_month_edited['p-_lag8'] = analysis_reg_month_edited['negative_change'].shift(8)
analysis_reg_month_edited['p-_lag9'] = analysis_reg_month_edited['negative_change'].shift(9)
analysis_reg_month_edited['p-_lag10'] = analysis_reg_month_edited['negative_change'].shift(10)


analysis_reg_month_edited = analysis_reg_month_edited.dropna()
In [169]:
analysis_reg_month_edited
Out[169]:
oil_spot_WTI Gasoline_Price_US co2_conc positive_change negative_change p+_lag1 p+_lag2 p+_lag3 p+_lag4 p+_lag5 ... p-_lag1 p-_lag2 p-_lag3 p-_lag4 p-_lag5 p-_lag6 p-_lag7 p-_lag8 p-_lag9 p-_lag10
Par_Month
199301 0.039240 -0.013183 0.002019 0.039240 0.000000 0.000000 0.000000 0.000000 0.009811 0.000000 ... -0.040227 -0.019039 -0.039351 0.000000 -0.024578 -0.026668 0.000000 0.000000 0.000000 0.000000
199302 0.012745 -0.007612 0.000324 0.012745 0.000000 0.039240 0.000000 0.000000 0.000000 0.009811 ... 0.000000 -0.040227 -0.019039 -0.039351 0.000000 -0.024578 -0.026668 0.000000 0.000000 0.000000
199303 -0.005372 0.008559 -0.000230 0.000000 -0.005372 0.012745 0.039240 0.000000 0.000000 0.000000 ... 0.000000 0.000000 -0.040227 -0.019039 -0.039351 0.000000 -0.024578 -0.026668 0.000000 0.000000
199304 0.005859 0.028013 -0.002067 0.005859 0.000000 0.000000 0.012745 0.039240 0.000000 0.000000 ... -0.005372 0.000000 0.000000 -0.040227 -0.019039 -0.039351 0.000000 -0.024578 -0.026668 0.000000
199305 -0.024644 0.018249 -0.002695 0.000000 -0.024644 0.005859 0.000000 0.012745 0.039240 0.000000 ... 0.000000 -0.005372 0.000000 0.000000 -0.040227 -0.019039 -0.039351 0.000000 -0.024578 -0.026668
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
202008 0.068893 0.002395 -0.002439 0.068893 0.000000 0.039939 0.079935 0.799539 0.032415 0.000000 ... 0.000000 0.000000 0.000000 0.000000 -1.063329 -0.140256 -0.180122 0.000000 0.000000 0.000000
202009 -0.069891 -0.005758 0.002333 0.000000 -0.069891 0.068893 0.039939 0.079935 0.799539 0.032415 ... 0.000000 0.000000 0.000000 0.000000 0.000000 -1.063329 -0.140256 -0.180122 0.000000 0.000000
202010 -0.116910 -0.012104 -0.002234 0.000000 -0.116910 0.000000 0.068893 0.039939 0.079935 0.799539 ... -0.069891 0.000000 0.000000 0.000000 0.000000 0.000000 -1.063329 -0.140256 -0.180122 0.000000
202011 0.219771 -0.021665 0.002038 0.219771 0.000000 0.000000 0.000000 0.068893 0.039939 0.079935 ... -0.116910 -0.069891 0.000000 0.000000 0.000000 0.000000 0.000000 -1.063329 -0.140256 -0.180122
202012 0.085227 0.071545 -0.001917 0.085227 0.000000 0.219771 0.000000 0.000000 0.068893 0.039939 ... 0.000000 -0.116910 -0.069891 0.000000 0.000000 0.000000 0.000000 0.000000 -1.063329 -0.140256

336 rows × 25 columns

In [170]:
#Monthly gas
x = analysis_reg_month_edited[['positive_change', 'negative_change','p+_lag1', 'p+_lag2',
       'p+_lag3', 'p+_lag4', 'p+_lag5', 'p+_lag6', 'p+_lag7', 'p+_lag8',
       'p+_lag9', 'p+_lag10', 'p-_lag1', 'p-_lag2', 'p-_lag3', 'p-_lag4',
       'p-_lag5', 'p-_lag6', 'p-_lag7', 'p-_lag8', 'p-_lag9', 'p-_lag10']] 

reg_model = sm.OLS(analysis_reg_month_edited['Gasoline_Price_US'],x)
result = reg_model.fit()
print(result.summary())
## Three years of emissions
                            OLS Regression Results                            
==============================================================================
Dep. Variable:      Gasoline_Price_US   R-squared:                       0.432
Model:                            OLS   Adj. R-squared:                  0.393
Method:                 Least Squares   F-statistic:                     10.88
Date:                Sun, 28 Feb 2021   Prob (F-statistic):           2.08e-27
Time:                        15:24:57   Log-Likelihood:                 530.33
No. Observations:                 336   AIC:                            -1017.
Df Residuals:                     314   BIC:                            -932.7
Df Model:                          22                                         
Covariance Type:            nonrobust                                         
===================================================================================
                      coef    std err          t      P>|t|      [0.025      0.975]
-----------------------------------------------------------------------------------
positive_change     0.3142      0.051      6.112      0.000       0.213       0.415
negative_change     0.2494      0.036      6.922      0.000       0.178       0.320
p+_lag1             0.2272      0.051      4.412      0.000       0.126       0.328
p+_lag2             0.0249      0.052      0.475      0.635      -0.078       0.128
p+_lag3             0.0095      0.053      0.181      0.856      -0.094       0.113
p+_lag4             0.0009      0.053      0.018      0.986      -0.103       0.105
p+_lag5            -0.0656      0.054     -1.225      0.222      -0.171       0.040
p+_lag6            -0.1519      0.053     -2.841      0.005      -0.257      -0.047
p+_lag7             0.0264      0.053      0.498      0.619      -0.078       0.131
p+_lag8             0.0719      0.059      1.222      0.222      -0.044       0.188
p+_lag9            -0.0406      0.058     -0.697      0.487      -0.155       0.074
p+_lag10            0.0243      0.057      0.423      0.673      -0.089       0.137
p-_lag1             0.1882      0.036      5.158      0.000       0.116       0.260
p-_lag2             0.0800      0.043      1.872      0.062      -0.004       0.164
p-_lag3             0.0408      0.043      0.953      0.341      -0.043       0.125
p-_lag4            -0.0427      0.043     -1.001      0.317      -0.127       0.041
p-_lag5            -0.0117      0.043     -0.269      0.788      -0.097       0.074
p-_lag6             0.0312      0.043      0.719      0.472      -0.054       0.117
p-_lag7            -0.0161      0.043     -0.370      0.712      -0.102       0.069
p-_lag8            -0.0885      0.044     -2.031      0.043      -0.174      -0.003
p-_lag9             0.0141      0.044      0.317      0.752      -0.073       0.102
p-_lag10           -0.0130      0.053     -0.245      0.807      -0.118       0.092
==============================================================================
Omnibus:                       18.559   Durbin-Watson:                   1.878
Prob(Omnibus):                  0.000   Jarque-Bera (JB):               52.025
Skew:                          -0.078   Prob(JB):                     5.05e-12
Kurtosis:                       4.921   Cond. No.                         5.54
==============================================================================

Warnings:
[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.
In [171]:
result.tvalues.to_frame()
Out[171]:
0
positive_change 6.111870
negative_change 6.921579
p+_lag1 4.412042
p+_lag2 0.475270
p+_lag3 0.181473
p+_lag4 0.017624
p+_lag5 -1.224952
p+_lag6 -2.841092
p+_lag7 0.498124
p+_lag8 1.222380
p+_lag9 -0.696602
p+_lag10 0.422820
p-_lag1 5.157838
p-_lag2 1.872129
p-_lag3 0.953422
p-_lag4 -1.001385
p-_lag5 -0.268715
p-_lag6 0.719288
p-_lag7 -0.370123
p-_lag8 -2.031419
p-_lag9 0.316936
p-_lag10 -0.244570
In [172]:
#Monthly Oil futures to future gasoline price
#Monthly
analysis = oil_co2_df.copy()
oil_co2_df.columns

analysis_month = analysis.groupby('Par_Month').last()[['future_oil_contract_1','Gasoline_Price_US','co2_conc']]

analysis_reg_month = np.log(analysis_month) - np.log(analysis_month.shift(1))
analysis_reg_month.dropna(inplace = True)
analysis_reg_month['co2_conc'] = analysis_reg_month['co2_conc'] - analysis_reg_month['co2_conc'].shift(12)
analysis_reg_month.dropna(inplace = True)

### Month ###
analysis_reg_month_edited = analysis_reg_month.copy()

analysis_reg_month_edited['positive_change'] = list(map(lambda x : 0 if x <= 0 else x,analysis_reg_month['future_oil_contract_1'] ))
analysis_reg_month_edited['negative_change'] = list(map(lambda x : 0 if x >= 0 else x,analysis_reg_month['future_oil_contract_1'] ))


analysis_reg_month_edited['p+_lag1'] = analysis_reg_month_edited['positive_change'].shift(1)
analysis_reg_month_edited['p+_lag2'] = analysis_reg_month_edited['positive_change'].shift(2)
analysis_reg_month_edited['p+_lag3'] = analysis_reg_month_edited['positive_change'].shift(3)
analysis_reg_month_edited['p+_lag4'] = analysis_reg_month_edited['positive_change'].shift(4)
analysis_reg_month_edited['p+_lag5'] = analysis_reg_month_edited['positive_change'].shift(5)
analysis_reg_month_edited['p+_lag6'] = analysis_reg_month_edited['positive_change'].shift(6)
analysis_reg_month_edited['p+_lag7'] = analysis_reg_month_edited['positive_change'].shift(7)
analysis_reg_month_edited['p+_lag8'] = analysis_reg_month_edited['positive_change'].shift(8)
analysis_reg_month_edited['p+_lag9'] = analysis_reg_month_edited['positive_change'].shift(9)
analysis_reg_month_edited['p+_lag10'] = analysis_reg_month_edited['positive_change'].shift(10)

analysis_reg_month_edited['chg_future_gasoline_lag-1'] = analysis_reg_month_edited['Gasoline_Price_US'].shift(-1)


analysis_reg_month_edited['p-_lag1'] = analysis_reg_month_edited['negative_change'].shift(1)
analysis_reg_month_edited['p-_lag2'] = analysis_reg_month_edited['negative_change'].shift(2)
analysis_reg_month_edited['p-_lag3'] = analysis_reg_month_edited['negative_change'].shift(3)
analysis_reg_month_edited['p-_lag4'] = analysis_reg_month_edited['negative_change'].shift(4)
analysis_reg_month_edited['p-_lag5'] = analysis_reg_month_edited['negative_change'].shift(5)
analysis_reg_month_edited['p-_lag6'] = analysis_reg_month_edited['negative_change'].shift(6)
analysis_reg_month_edited['p-_lag7'] = analysis_reg_month_edited['negative_change'].shift(7)
analysis_reg_month_edited['p-_lag8'] = analysis_reg_month_edited['negative_change'].shift(8)
analysis_reg_month_edited['p-_lag9'] = analysis_reg_month_edited['negative_change'].shift(9)
analysis_reg_month_edited['p-_lag10'] = analysis_reg_month_edited['negative_change'].shift(10)


analysis_reg_month_edited = analysis_reg_month_edited.dropna()


#Monthly oil futures to future gasoline
x = analysis_reg_month_edited[['positive_change', 'negative_change','p+_lag1', 'p+_lag2',
       'p+_lag3', 'p+_lag4', 'p+_lag5', 'p+_lag6', 'p+_lag7', 'p+_lag8',
       'p+_lag9', 'p+_lag10', 'p-_lag1', 'p-_lag2', 'p-_lag3', 'p-_lag4',
       'p-_lag5', 'p-_lag6', 'p-_lag7', 'p-_lag8', 'p-_lag9', 'p-_lag10']] 

reg_model = sm.OLS(analysis_reg_month_edited['chg_future_gasoline_lag-1'],x)
result = reg_model.fit()
print(result.summary())
## Three years of emissions
                                OLS Regression Results                               
=====================================================================================
Dep. Variable:     chg_future_gasoline_lag-1   R-squared:                       0.252
Model:                                   OLS   Adj. R-squared:                  0.199
Method:                        Least Squares   F-statistic:                     4.787
Date:                       Sun, 28 Feb 2021   Prob (F-statistic):           8.33e-11
Time:                               15:24:57   Log-Likelihood:                 481.96
No. Observations:                        335   AIC:                            -919.9
Df Residuals:                            313   BIC:                            -836.0
Df Model:                                 22                                         
Covariance Type:                   nonrobust                                         
===================================================================================
                      coef    std err          t      P>|t|      [0.025      0.975]
-----------------------------------------------------------------------------------
positive_change     0.1879      0.061      3.083      0.002       0.068       0.308
negative_change     0.2971      0.051      5.865      0.000       0.197       0.397
p+_lag1             0.0779      0.061      1.273      0.204      -0.043       0.198
p+_lag2             0.0003      0.063      0.004      0.997      -0.123       0.123
p+_lag3            -0.0164      0.063     -0.261      0.794      -0.140       0.107
p+_lag4            -0.0212      0.063     -0.335      0.738      -0.145       0.103
p+_lag5            -0.1298      0.065     -2.010      0.045      -0.257      -0.003
p+_lag6            -0.0124      0.063     -0.195      0.845      -0.137       0.112
p+_lag7             0.0452      0.074      0.613      0.541      -0.100       0.190
p+_lag8            -0.0871      0.073     -1.196      0.233      -0.230       0.056
p+_lag9            -0.0133      0.071     -0.186      0.852      -0.154       0.127
p+_lag10            0.2096      0.071      2.959      0.003       0.070       0.349
p-_lag1            -0.0477      0.053     -0.903      0.367      -0.152       0.056
p-_lag2             0.0154      0.058      0.266      0.791      -0.099       0.129
p-_lag3            -0.0281      0.058     -0.484      0.628      -0.142       0.086
p-_lag4            -0.0823      0.058     -1.429      0.154      -0.196       0.031
p-_lag5             0.0394      0.058      0.674      0.501      -0.076       0.154
p-_lag6             0.0326      0.058      0.558      0.577      -0.082       0.148
p-_lag7            -0.1204      0.059     -2.034      0.043      -0.237      -0.004
p-_lag8             0.0124      0.059      0.210      0.833      -0.104       0.128
p-_lag9            -0.0229      0.064     -0.355      0.723      -0.150       0.104
p-_lag10            0.0830      0.063      1.315      0.189      -0.041       0.207
==============================================================================
Omnibus:                       44.469   Durbin-Watson:                   1.913
Prob(Omnibus):                  0.000   Jarque-Bera (JB):              200.875
Skew:                          -0.423   Prob(JB):                     2.40e-44
Kurtosis:                       6.698   Cond. No.                         5.64
==============================================================================

Warnings:
[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.
In [173]:
result.tvalues.to_frame()
Out[173]:
0
positive_change 3.083138
negative_change 5.864623
p+_lag1 1.272582
p+_lag2 0.004194
p+_lag3 -0.260988
p+_lag4 -0.335036
p+_lag5 -2.009712
p+_lag6 -0.195246
p+_lag7 0.612580
p+_lag8 -1.195916
p+_lag9 -0.186465
p+_lag10 2.959286
p-_lag1 -0.903241
p-_lag2 0.265786
p-_lag3 -0.484423
p-_lag4 -1.429377
p-_lag5 0.674427
p-_lag6 0.558243
p-_lag7 -2.033920
p-_lag8 0.210435
p-_lag9 -0.354937
p-_lag10 1.315040
In [174]:
#Monthly CO2
x = analysis_reg_month_edited[['positive_change', 'negative_change','p+_lag1', 'p+_lag2',
       'p+_lag3', 'p+_lag4', 'p+_lag5', 'p+_lag6', 'p+_lag7', 'p+_lag8',
       'p+_lag9', 'p+_lag10', 'p-_lag1', 'p-_lag2', 'p-_lag3', 'p-_lag4',
       'p-_lag5', 'p-_lag6', 'p-_lag7', 'p-_lag8', 'p-_lag9', 'p-_lag10']] 

reg_model = sm.OLS(analysis_reg_month_edited['co2_conc'],x)
result = reg_model.fit()
print(result.summary())
## Three years of emissions
                            OLS Regression Results                            
==============================================================================
Dep. Variable:               co2_conc   R-squared:                       0.100
Model:                            OLS   Adj. R-squared:                  0.037
Method:                 Least Squares   F-statistic:                     1.583
Date:                Sun, 28 Feb 2021   Prob (F-statistic):             0.0485
Time:                        15:24:57   Log-Likelihood:                 1591.0
No. Observations:                 335   AIC:                            -3138.
Df Residuals:                     313   BIC:                            -3054.
Df Model:                          22                                         
Covariance Type:            nonrobust                                         
===================================================================================
                      coef    std err          t      P>|t|      [0.025      0.975]
-----------------------------------------------------------------------------------
positive_change     0.0006      0.002      0.262      0.793      -0.004       0.005
negative_change    -0.0005      0.002     -0.261      0.794      -0.004       0.003
p+_lag1            -0.0005      0.002     -0.229      0.819      -0.005       0.004
p+_lag2            -0.0009      0.002     -0.385      0.701      -0.005       0.004
p+_lag3             0.0028      0.002      1.221      0.223      -0.002       0.007
p+_lag4            -0.0036      0.002     -1.566      0.118      -0.008       0.001
p+_lag5            -0.0026      0.002     -1.085      0.279      -0.007       0.002
p+_lag6             0.0052      0.002      2.265      0.024       0.001       0.010
p+_lag7            -0.0001      0.003     -0.052      0.959      -0.005       0.005
p+_lag8            -0.0021      0.003     -0.799      0.425      -0.007       0.003
p+_lag9             0.0004      0.003      0.167      0.868      -0.005       0.006
p+_lag10            0.0014      0.003      0.555      0.579      -0.004       0.007
p-_lag1             0.0002      0.002      0.107      0.915      -0.004       0.004
p-_lag2            -0.0021      0.002     -0.993      0.322      -0.006       0.002
p-_lag3             0.0033      0.002      1.581      0.115      -0.001       0.008
p-_lag4            -0.0035      0.002     -1.680      0.094      -0.008       0.001
p-_lag5             0.0052      0.002      2.455      0.015       0.001       0.009
p-_lag6            -0.0072      0.002     -3.396      0.001      -0.011      -0.003
p-_lag7             0.0030      0.002      1.385      0.167      -0.001       0.007
p-_lag8             0.0009      0.002      0.441      0.659      -0.003       0.005
p-_lag9            -0.0003      0.002     -0.115      0.908      -0.005       0.004
p-_lag10            0.0012      0.002      0.526      0.599      -0.003       0.006
==============================================================================
Omnibus:                        0.053   Durbin-Watson:                   2.948
Prob(Omnibus):                  0.974   Jarque-Bera (JB):                0.116
Skew:                           0.027   Prob(JB):                        0.944
Kurtosis:                       2.927   Cond. No.                         5.64
==============================================================================

Warnings:
[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.
In [175]:
result.tvalues.to_frame()
Out[175]:
0
positive_change 0.262101
negative_change -0.260991
p+_lag1 -0.229169
p+_lag2 -0.384599
p+_lag3 1.220802
p+_lag4 -1.566402
p+_lag5 -1.085334
p+_lag6 2.264646
p+_lag7 -0.051740
p+_lag8 -0.798802
p+_lag9 0.166775
p+_lag10 0.555449
p-_lag1 0.106905
p-_lag2 -0.992736
p-_lag3 1.581199
p-_lag4 -1.679887
p-_lag5 2.454698
p-_lag6 -3.395627
p-_lag7 1.385424
p-_lag8 0.441120
p-_lag9 -0.115409
p-_lag10 0.526432
In [176]:
### Weekly CO2 ###
### Weekly Lag 0###

analysis = oil_co2_df.copy()
oil_co2_df.columns

analysis_month = analysis.groupby('Par_Month').last()[['oil_spot_WTI','Gasoline_Price_US','co2_conc']]

analysis_reg_month = np.log(analysis_month) - np.log(analysis_month.shift(1))
analysis_reg_month.dropna(inplace = True)
analysis_reg_month['co2_conc'] = analysis_reg_month['co2_conc'] - analysis_reg_month['co2_conc'].shift(12)
analysis_reg_month.dropna(inplace = True)

analysis_reg_month_edited = analysis_reg_month.copy()

analysis_reg_month_edited['chg_oil_spot_WTI_Positive'] = list(map(lambda x : 0 if x <= 0 else x,analysis_reg_month['oil_spot_WTI'] ))
analysis_reg_month_edited['chg_oil_spot_WTI_Negative'] = list(map(lambda x : 0 if x >= 0 else x,analysis_reg_month['oil_spot_WTI'] ))

analysis_reg = analysis_reg_month_edited.copy()

x = analysis_reg[['chg_oil_spot_WTI_Positive', 'chg_oil_spot_WTI_Negative']] 

reg_model = sm.OLS(analysis_reg['Gasoline_Price_US'],x)
result = reg_model.fit()
print(result.summary())

### Weekly ###
### Weekly Lag 3###

analysis = oil_co2_df.copy()
oil_co2_df.columns

analysis_month = analysis.groupby('Par_Month').last()[['oil_spot_WTI','Gasoline_Price_US','co2_conc']]

analysis_reg_month = np.log(analysis_month) - np.log(analysis_month.shift(1))
analysis_reg_month.dropna(inplace = True)
analysis_reg_month['co2_conc'] = analysis_reg_month['co2_conc'] - analysis_reg_month['co2_conc'].shift(12)
analysis_reg_month.dropna(inplace = True)

analysis_reg_month_edited = analysis_reg_month.copy()

analysis_reg_month_edited['chg_oil_spot_WTI_Positive'] = list(map(lambda x : 0 if x <= 0 else x,analysis_reg_month['oil_spot_WTI'] ))
analysis_reg_month_edited['chg_oil_spot_WTI_Negative'] = list(map(lambda x : 0 if x >= 0 else x,analysis_reg_month['oil_spot_WTI'] ))

analysis_reg = analysis_reg_month_edited.copy()


analysis_reg['p+_lag1'] = analysis_reg_month_edited['chg_oil_spot_WTI_Positive'].shift(1)
analysis_reg['p+_lag2'] = analysis_reg_month_edited['chg_oil_spot_WTI_Positive'].shift(2)
analysis_reg['p+_lag3'] = analysis_reg_month_edited['chg_oil_spot_WTI_Positive'].shift(3)


analysis_reg['p-_lag1'] = analysis_reg_month_edited['chg_oil_spot_WTI_Negative'].shift(1)
analysis_reg['p-_lag2'] = analysis_reg_month_edited['chg_oil_spot_WTI_Negative'].shift(2)
analysis_reg['p-_lag3'] = analysis_reg_month_edited['chg_oil_spot_WTI_Negative'].shift(3)


analysis_reg = analysis_reg.dropna(subset = ['p+_lag1','p-_lag1','p+_lag2','p-_lag2','p+_lag3','p-_lag3'])

x = analysis_reg[['chg_oil_spot_WTI_Positive', 'chg_oil_spot_WTI_Negative','p+_lag1','p-_lag1','p+_lag2','p-_lag2','p+_lag3','p-_lag3']] 

reg_model = sm.OLS(analysis_reg['Gasoline_Price_US'],x)
result = reg_model.fit()
print(result.summary())


### Weekly ###
### Weekly Lag 6###

analysis = oil_co2_df.copy()
oil_co2_df.columns

analysis_month = analysis.groupby('Par_Month').last()[['oil_spot_WTI','Gasoline_Price_US','co2_conc']]

analysis_reg_month = np.log(analysis_month) - np.log(analysis_month.shift(1))
analysis_reg_month.dropna(inplace = True)
analysis_reg_month['co2_conc'] = analysis_reg_month['co2_conc'] - analysis_reg_month['co2_conc'].shift(12)
analysis_reg_month.dropna(inplace = True)

analysis_reg_month_edited = analysis_reg_month.copy()

analysis_reg_month_edited['chg_oil_spot_WTI_Positive'] = list(map(lambda x : 0 if x <= 0 else x,analysis_reg_month['oil_spot_WTI'] ))
analysis_reg_month_edited['chg_oil_spot_WTI_Negative'] = list(map(lambda x : 0 if x >= 0 else x,analysis_reg_month['oil_spot_WTI'] ))

analysis_reg = analysis_reg_month_edited.copy()


analysis_reg['p+_lag1'] = analysis_reg_month_edited['chg_oil_spot_WTI_Positive'].shift(1)
analysis_reg['p+_lag2'] = analysis_reg_month_edited['chg_oil_spot_WTI_Positive'].shift(2)
analysis_reg['p+_lag3'] = analysis_reg_month_edited['chg_oil_spot_WTI_Positive'].shift(3)
analysis_reg['p+_lag4'] = analysis_reg_month_edited['chg_oil_spot_WTI_Positive'].shift(4)
analysis_reg['p+_lag5'] = analysis_reg_month_edited['chg_oil_spot_WTI_Positive'].shift(5)
analysis_reg['p+_lag6'] = analysis_reg_month_edited['chg_oil_spot_WTI_Positive'].shift(6)

analysis_reg['p-_lag1'] = analysis_reg_month_edited['chg_oil_spot_WTI_Negative'].shift(1)
analysis_reg['p-_lag2'] = analysis_reg_month_edited['chg_oil_spot_WTI_Negative'].shift(2)
analysis_reg['p-_lag3'] = analysis_reg_month_edited['chg_oil_spot_WTI_Negative'].shift(3)
analysis_reg['p-_lag4'] = analysis_reg_month_edited['chg_oil_spot_WTI_Negative'].shift(4)
analysis_reg['p-_lag5'] = analysis_reg_month_edited['chg_oil_spot_WTI_Negative'].shift(5)
analysis_reg['p-_lag6'] = analysis_reg_month_edited['chg_oil_spot_WTI_Negative'].shift(6)


analysis_reg = analysis_reg.dropna(subset = ['p+_lag1','p-_lag1','p+_lag2','p-_lag2','p+_lag3','p-_lag3','p+_lag4','p-_lag4','p+_lag5','p-_lag5','p+_lag6','p-_lag6'])

x = analysis_reg[['chg_oil_spot_WTI_Positive', 'chg_oil_spot_WTI_Negative','p+_lag1','p-_lag1','p+_lag2','p-_lag2','p+_lag3','p-_lag3','p+_lag4','p-_lag4','p+_lag5','p-_lag5','p+_lag6','p-_lag6']] 

reg_model = sm.OLS(analysis_reg['Gasoline_Price_US'],x)
result = reg_model.fit()
print(result.summary())


### Weekly ###
### Weekly Lag 12###

analysis = oil_co2_df.copy()
oil_co2_df.columns

analysis_month = analysis.groupby('Par_Month').last()[['oil_spot_WTI','Gasoline_Price_US','co2_conc']]

analysis_reg_month = np.log(analysis_month) - np.log(analysis_month.shift(1))
analysis_reg_month.dropna(inplace = True)
analysis_reg_month['co2_conc'] = analysis_reg_month['co2_conc'] - analysis_reg_month['co2_conc'].shift(12)
analysis_reg_month.dropna(inplace = True)

analysis_reg_month_edited = analysis_reg_month.copy()

analysis_reg_month_edited['chg_oil_spot_WTI_Positive'] = list(map(lambda x : 0 if x <= 0 else x,analysis_reg_month['oil_spot_WTI'] ))
analysis_reg_month_edited['chg_oil_spot_WTI_Negative'] = list(map(lambda x : 0 if x >= 0 else x,analysis_reg_month['oil_spot_WTI'] ))

analysis_reg = analysis_reg_month_edited.copy()

analysis_reg['p+_lag1'] = analysis_reg_month_edited['chg_oil_spot_WTI_Positive'].shift(1)
analysis_reg['p+_lag2'] = analysis_reg_month_edited['chg_oil_spot_WTI_Positive'].shift(2)
analysis_reg['p+_lag3'] = analysis_reg_month_edited['chg_oil_spot_WTI_Positive'].shift(3)
analysis_reg['p+_lag4'] = analysis_reg_month_edited['chg_oil_spot_WTI_Positive'].shift(4)
analysis_reg['p+_lag5'] = analysis_reg_month_edited['chg_oil_spot_WTI_Positive'].shift(5)
analysis_reg['p+_lag6'] = analysis_reg_month_edited['chg_oil_spot_WTI_Positive'].shift(6)
analysis_reg['p+_lag7'] = analysis_reg_month_edited['chg_oil_spot_WTI_Positive'].shift(7)
analysis_reg['p+_lag8'] = analysis_reg_month_edited['chg_oil_spot_WTI_Positive'].shift(8)
analysis_reg['p+_lag9'] = analysis_reg_month_edited['chg_oil_spot_WTI_Positive'].shift(9)
analysis_reg['p+_lag10'] = analysis_reg_month_edited['chg_oil_spot_WTI_Positive'].shift(10)
analysis_reg['p+_lag11'] = analysis_reg_month_edited['chg_oil_spot_WTI_Positive'].shift(11)
analysis_reg['p+_lag12'] = analysis_reg_month_edited['chg_oil_spot_WTI_Positive'].shift(12)

analysis_reg['p-_lag1'] = analysis_reg_month_edited['chg_oil_spot_WTI_Negative'].shift(1)
analysis_reg['p-_lag2'] = analysis_reg_month_edited['chg_oil_spot_WTI_Negative'].shift(2)
analysis_reg['p-_lag3'] = analysis_reg_month_edited['chg_oil_spot_WTI_Negative'].shift(3)
analysis_reg['p-_lag4'] = analysis_reg_month_edited['chg_oil_spot_WTI_Negative'].shift(4)
analysis_reg['p-_lag5'] = analysis_reg_month_edited['chg_oil_spot_WTI_Negative'].shift(5)
analysis_reg['p-_lag6'] = analysis_reg_month_edited['chg_oil_spot_WTI_Negative'].shift(6)
analysis_reg['p-_lag7'] = analysis_reg_month_edited['chg_oil_spot_WTI_Negative'].shift(7)
analysis_reg['p-_lag8'] = analysis_reg_month_edited['chg_oil_spot_WTI_Negative'].shift(8)
analysis_reg['p-_lag9'] = analysis_reg_month_edited['chg_oil_spot_WTI_Negative'].shift(9)
analysis_reg['p-_lag10'] = analysis_reg_month_edited['chg_oil_spot_WTI_Negative'].shift(10)
analysis_reg['p-_lag11'] = analysis_reg_month_edited['chg_oil_spot_WTI_Negative'].shift(11)
analysis_reg['p-_lag12'] = analysis_reg_month_edited['chg_oil_spot_WTI_Negative'].shift(12)


analysis_reg = analysis_reg.dropna(subset = ['p+_lag1','p-_lag1','p+_lag2','p-_lag2','p+_lag3','p-_lag3','p+_lag4','p-_lag4','p+_lag5','p-_lag5','p+_lag6','p-_lag6','p+_lag7','p-_lag7','p+_lag8','p-_lag8','p+_lag9','p-_lag9','p+_lag10','p-_lag10','p+_lag11','p-_lag11','p+_lag12','p-_lag12'])

x = analysis_reg[['chg_oil_spot_WTI_Positive', 'chg_oil_spot_WTI_Negative','p+_lag1','p-_lag1','p+_lag2','p-_lag2','p+_lag3','p-_lag3','p+_lag4','p-_lag4','p+_lag5','p-_lag5','p+_lag6','p-_lag6','p+_lag7','p-_lag7','p+_lag8','p-_lag8','p+_lag9','p-_lag9','p+_lag10','p-_lag10','p+_lag11','p-_lag11','p+_lag12','p-_lag12']] 

reg_model = sm.OLS(analysis_reg['Gasoline_Price_US'],x)
result = reg_model.fit()
print(result.summary())


### Weekly ###
### Weekly Lag 24###

analysis = oil_co2_df.copy()
oil_co2_df.columns

analysis_month = analysis.groupby('Par_Month').last()[['oil_spot_WTI','Gasoline_Price_US','co2_conc']]

analysis_reg_month = np.log(analysis_month) - np.log(analysis_month.shift(1))
analysis_reg_month.dropna(inplace = True)
analysis_reg_month['co2_conc'] = analysis_reg_month['co2_conc'] - analysis_reg_month['co2_conc'].shift(12)
analysis_reg_month.dropna(inplace = True)

analysis_reg_month_edited = analysis_reg_month.copy()

analysis_reg_month_edited['chg_oil_spot_WTI_Positive'] = list(map(lambda x : 0 if x <= 0 else x,analysis_reg_month['oil_spot_WTI'] ))
analysis_reg_month_edited['chg_oil_spot_WTI_Negative'] = list(map(lambda x : 0 if x >= 0 else x,analysis_reg_month['oil_spot_WTI'] ))

analysis_reg = analysis_reg_month_edited.copy()

analysis_reg_month_edited['chg_oil_spot_WTI_Positive'] = list(map(lambda x : 0 if x <= 0 else x,analysis_reg_month['oil_spot_WTI'] ))
analysis_reg_month_edited['chg_oil_spot_WTI_Negative'] = list(map(lambda x : 0 if x >= 0 else x,analysis_reg_month['oil_spot_WTI'] ))

analysis_reg = analysis_reg_month_edited.copy()
analysis_reg['p+_lag1'] = analysis_reg_month_edited['chg_oil_spot_WTI_Positive'].shift(1)
analysis_reg['p+_lag2'] = analysis_reg_month_edited['chg_oil_spot_WTI_Positive'].shift(2)
analysis_reg['p+_lag3'] = analysis_reg_month_edited['chg_oil_spot_WTI_Positive'].shift(3)
analysis_reg['p+_lag4'] = analysis_reg_month_edited['chg_oil_spot_WTI_Positive'].shift(4)
analysis_reg['p+_lag5'] = analysis_reg_month_edited['chg_oil_spot_WTI_Positive'].shift(5)
analysis_reg['p+_lag6'] = analysis_reg_month_edited['chg_oil_spot_WTI_Positive'].shift(6)
analysis_reg['p+_lag7'] = analysis_reg_month_edited['chg_oil_spot_WTI_Positive'].shift(7)
analysis_reg['p+_lag8'] = analysis_reg_month_edited['chg_oil_spot_WTI_Positive'].shift(8)
analysis_reg['p+_lag9'] = analysis_reg_month_edited['chg_oil_spot_WTI_Positive'].shift(9)
analysis_reg['p+_lag10'] = analysis_reg_month_edited['chg_oil_spot_WTI_Positive'].shift(10)
analysis_reg['p+_lag11'] = analysis_reg_month_edited['chg_oil_spot_WTI_Positive'].shift(11)
analysis_reg['p+_lag12'] = analysis_reg_month_edited['chg_oil_spot_WTI_Positive'].shift(12)
analysis_reg['p+_lag13'] = analysis_reg_month_edited['chg_oil_spot_WTI_Positive'].shift(13)
analysis_reg['p+_lag14'] = analysis_reg_month_edited['chg_oil_spot_WTI_Positive'].shift(14)
analysis_reg['p+_lag15'] = analysis_reg_month_edited['chg_oil_spot_WTI_Positive'].shift(15)
analysis_reg['p+_lag16'] = analysis_reg_month_edited['chg_oil_spot_WTI_Positive'].shift(16)
analysis_reg['p+_lag17'] = analysis_reg_month_edited['chg_oil_spot_WTI_Positive'].shift(17)
analysis_reg['p+_lag18'] = analysis_reg_month_edited['chg_oil_spot_WTI_Positive'].shift(18)
analysis_reg['p+_lag19'] = analysis_reg_month_edited['chg_oil_spot_WTI_Positive'].shift(19)
analysis_reg['p+_lag20'] = analysis_reg_month_edited['chg_oil_spot_WTI_Positive'].shift(20)
analysis_reg['p+_lag21'] = analysis_reg_month_edited['chg_oil_spot_WTI_Positive'].shift(21)
analysis_reg['p+_lag22'] = analysis_reg_month_edited['chg_oil_spot_WTI_Positive'].shift(22)
analysis_reg['p+_lag23'] = analysis_reg_month_edited['chg_oil_spot_WTI_Positive'].shift(23)
analysis_reg['p+_lag24'] = analysis_reg_month_edited['chg_oil_spot_WTI_Positive'].shift(24)

analysis_reg['p-_lag1'] = analysis_reg_month_edited['chg_oil_spot_WTI_Negative'].shift(1)
analysis_reg['p-_lag2'] = analysis_reg_month_edited['chg_oil_spot_WTI_Negative'].shift(2)
analysis_reg['p-_lag3'] = analysis_reg_month_edited['chg_oil_spot_WTI_Negative'].shift(3)
analysis_reg['p-_lag4'] = analysis_reg_month_edited['chg_oil_spot_WTI_Negative'].shift(4)
analysis_reg['p-_lag5'] = analysis_reg_month_edited['chg_oil_spot_WTI_Negative'].shift(5)
analysis_reg['p-_lag6'] = analysis_reg_month_edited['chg_oil_spot_WTI_Negative'].shift(6)
analysis_reg['p-_lag7'] = analysis_reg_month_edited['chg_oil_spot_WTI_Negative'].shift(7)
analysis_reg['p-_lag8'] = analysis_reg_month_edited['chg_oil_spot_WTI_Negative'].shift(8)
analysis_reg['p-_lag9'] = analysis_reg_month_edited['chg_oil_spot_WTI_Negative'].shift(9)
analysis_reg['p-_lag10'] = analysis_reg_month_edited['chg_oil_spot_WTI_Negative'].shift(10)
analysis_reg['p-_lag11'] = analysis_reg_month_edited['chg_oil_spot_WTI_Negative'].shift(11)
analysis_reg['p-_lag12'] = analysis_reg_month_edited['chg_oil_spot_WTI_Negative'].shift(12)
analysis_reg['p-_lag13'] = analysis_reg_month_edited['chg_oil_spot_WTI_Negative'].shift(13)
analysis_reg['p-_lag14'] = analysis_reg_month_edited['chg_oil_spot_WTI_Negative'].shift(14)
analysis_reg['p-_lag15'] = analysis_reg_month_edited['chg_oil_spot_WTI_Negative'].shift(15)
analysis_reg['p-_lag16'] = analysis_reg_month_edited['chg_oil_spot_WTI_Negative'].shift(16)
analysis_reg['p-_lag17'] = analysis_reg_month_edited['chg_oil_spot_WTI_Negative'].shift(17)
analysis_reg['p-_lag18'] = analysis_reg_month_edited['chg_oil_spot_WTI_Negative'].shift(18)
analysis_reg['p-_lag19'] = analysis_reg_month_edited['chg_oil_spot_WTI_Negative'].shift(19)
analysis_reg['p-_lag20'] = analysis_reg_month_edited['chg_oil_spot_WTI_Negative'].shift(20)
analysis_reg['p-_lag21'] = analysis_reg_month_edited['chg_oil_spot_WTI_Negative'].shift(21)
analysis_reg['p-_lag22'] = analysis_reg_month_edited['chg_oil_spot_WTI_Negative'].shift(22)
analysis_reg['p-_lag23'] = analysis_reg_month_edited['chg_oil_spot_WTI_Negative'].shift(23)
analysis_reg['p-_lag24'] = analysis_reg_month_edited['chg_oil_spot_WTI_Negative'].shift(24)


analysis_reg = analysis_reg.dropna(subset = ['p+_lag1','p-_lag1','p+_lag2','p-_lag2','p+_lag3','p-_lag3','p+_lag4','p-_lag4','p+_lag5','p-_lag5','p+_lag6','p-_lag6','p+_lag7','p-_lag7','p+_lag8','p-_lag8','p+_lag9','p-_lag9','p+_lag10','p-_lag10','p+_lag11','p-_lag11','p+_lag12','p-_lag12'
                                             ,'p+_lag13','p-_lag13','p+_lag14','p-_lag14','p+_lag15','p-_lag15','p+_lag16','p-_lag16','p+_lag17','p-_lag17','p+_lag18','p-_lag18','p+_lag19','p-_lag19','p+_lag20','p-_lag20','p+_lag21','p-_lag21','p+_lag22','p-_lag22','p+_lag23','p-_lag23','p+_lag24','p-_lag24'])

x = analysis_reg[['chg_oil_spot_WTI_Positive', 'chg_oil_spot_WTI_Negative','p+_lag1','p-_lag1','p+_lag2','p-_lag2','p+_lag3','p-_lag3','p+_lag4','p-_lag4','p+_lag5','p-_lag5','p+_lag6','p-_lag6','p+_lag7','p-_lag7','p+_lag8','p-_lag8','p+_lag9','p-_lag9','p+_lag10','p-_lag10','p+_lag11','p-_lag11','p+_lag12','p-_lag12'
                                             ,'p+_lag13','p-_lag13','p+_lag14','p-_lag14','p+_lag15','p-_lag15','p+_lag16','p-_lag16','p+_lag17','p-_lag17','p+_lag18','p-_lag18','p+_lag19','p-_lag19','p+_lag20','p-_lag20','p+_lag21','p-_lag21','p+_lag22','p-_lag22','p+_lag23','p-_lag23','p+_lag24','p-_lag24']] 

reg_model = sm.OLS(analysis_reg['Gasoline_Price_US'],x)
result = reg_model.fit()
print(result.summary())
                            OLS Regression Results                            
==============================================================================
Dep. Variable:      Gasoline_Price_US   R-squared:                       0.260
Model:                            OLS   Adj. R-squared:                  0.255
Method:                 Least Squares   F-statistic:                     60.34
Date:                Sun, 28 Feb 2021   Prob (F-statistic):           3.45e-23
Time:                        15:24:57   Log-Likelihood:                 504.32
No. Observations:                 346   AIC:                            -1005.
Df Residuals:                     344   BIC:                            -996.9
Df Model:                           2                                         
Covariance Type:            nonrobust                                         
=============================================================================================
                                coef    std err          t      P>|t|      [0.025      0.975]
---------------------------------------------------------------------------------------------
chg_oil_spot_WTI_Positive     0.2571      0.039      6.625      0.000       0.181       0.333
chg_oil_spot_WTI_Negative     0.2923      0.033      8.763      0.000       0.227       0.358
==============================================================================
Omnibus:                       39.101   Durbin-Watson:                   1.788
Prob(Omnibus):                  0.000   Jarque-Bera (JB):              106.392
Skew:                          -0.515   Prob(JB):                     7.89e-24
Kurtosis:                       5.513   Cond. No.                         1.16
==============================================================================

Warnings:
[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.
                            OLS Regression Results                            
==============================================================================
Dep. Variable:      Gasoline_Price_US   R-squared:                       0.409
Model:                            OLS   Adj. R-squared:                  0.395
Method:                 Least Squares   F-statistic:                     29.01
Date:                Sun, 28 Feb 2021   Prob (F-statistic):           2.94e-34
Time:                        15:24:57   Log-Likelihood:                 537.72
No. Observations:                 343   AIC:                            -1059.
Df Residuals:                     335   BIC:                            -1029.
Df Model:                           8                                         
Covariance Type:            nonrobust                                         
=============================================================================================
                                coef    std err          t      P>|t|      [0.025      0.975]
---------------------------------------------------------------------------------------------
chg_oil_spot_WTI_Positive     0.2983      0.048      6.198      0.000       0.204       0.393
chg_oil_spot_WTI_Negative     0.2583      0.034      7.510      0.000       0.191       0.326
p+_lag1                       0.2138      0.047      4.527      0.000       0.121       0.307
p-_lag1                       0.1958      0.035      5.616      0.000       0.127       0.264
p+_lag2                       0.0389      0.041      0.947      0.344      -0.042       0.120
p-_lag2                       0.0743      0.040      1.843      0.066      -0.005       0.154
p+_lag3                       0.0257      0.041      0.619      0.536      -0.056       0.107
p-_lag3                       0.0301      0.040      0.744      0.457      -0.050       0.110
==============================================================================
Omnibus:                       22.494   Durbin-Watson:                   1.866
Prob(Omnibus):                  0.000   Jarque-Bera (JB):               75.640
Skew:                          -0.011   Prob(JB):                     3.76e-17
Kurtosis:                       5.300   Cond. No.                         3.13
==============================================================================

Warnings:
[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.
                            OLS Regression Results                            
==============================================================================
Dep. Variable:      Gasoline_Price_US   R-squared:                       0.422
Model:                            OLS   Adj. R-squared:                  0.398
Method:                 Least Squares   F-statistic:                     17.03
Date:                Sun, 28 Feb 2021   Prob (F-statistic):           2.46e-31
Time:                        15:24:57   Log-Likelihood:                 535.52
No. Observations:                 340   AIC:                            -1043.
Df Residuals:                     326   BIC:                            -989.4
Df Model:                          14                                         
Covariance Type:            nonrobust                                         
=============================================================================================
                                coef    std err          t      P>|t|      [0.025      0.975]
---------------------------------------------------------------------------------------------
chg_oil_spot_WTI_Positive     0.3235      0.050      6.417      0.000       0.224       0.423
chg_oil_spot_WTI_Negative     0.2445      0.035      6.951      0.000       0.175       0.314
p+_lag1                       0.2311      0.050      4.643      0.000       0.133       0.329
p-_lag1                       0.1833      0.036      5.157      0.000       0.113       0.253
p+_lag2                       0.0287      0.050      0.568      0.570      -0.071       0.128
p-_lag2                       0.0830      0.042      1.983      0.048       0.001       0.165
p+_lag3                       0.0341      0.050      0.677      0.499      -0.065       0.133
p-_lag3                       0.0370      0.042      0.881      0.379      -0.046       0.120
p+_lag4                       0.0093      0.050      0.185      0.853      -0.089       0.108
p-_lag4                      -0.0440      0.042     -1.051      0.294      -0.126       0.038
p+_lag5                      -0.0403      0.043     -0.942      0.347      -0.125       0.044
p-_lag5                      -0.0062      0.042     -0.150      0.881      -0.088       0.075
p+_lag6                      -0.0894      0.043     -2.061      0.040      -0.175      -0.004
p-_lag6                       0.0115      0.041      0.277      0.782      -0.070       0.093
==============================================================================
Omnibus:                       20.359   Durbin-Watson:                   1.877
Prob(Omnibus):                  0.000   Jarque-Bera (JB):               60.607
Skew:                          -0.094   Prob(JB):                     6.91e-14
Kurtosis:                       5.060   Cond. No.                         4.25
==============================================================================

Warnings:
[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.
                            OLS Regression Results                            
==============================================================================
Dep. Variable:      Gasoline_Price_US   R-squared:                       0.454
Model:                            OLS   Adj. R-squared:                  0.408
Method:                 Least Squares   F-statistic:                     9.841
Date:                Sun, 28 Feb 2021   Prob (F-statistic):           1.84e-27
Time:                        15:24:57   Log-Likelihood:                 532.58
No. Observations:                 334   AIC:                            -1013.
Df Residuals:                     308   BIC:                            -914.1
Df Model:                          26                                         
Covariance Type:            nonrobust                                         
=============================================================================================
                                coef    std err          t      P>|t|      [0.025      0.975]
---------------------------------------------------------------------------------------------
chg_oil_spot_WTI_Positive     0.2883      0.053      5.462      0.000       0.184       0.392
chg_oil_spot_WTI_Negative     0.2589      0.036      7.120      0.000       0.187       0.330
p+_lag1                       0.2169      0.052      4.152      0.000       0.114       0.320
p-_lag1                       0.1907      0.036      5.257      0.000       0.119       0.262
p+_lag2                       0.0340      0.052      0.654      0.514      -0.068       0.136
p-_lag2                       0.0648      0.043      1.518      0.130      -0.019       0.149
p+_lag3                       0.0087      0.052      0.166      0.868      -0.094       0.111
p-_lag3                       0.0412      0.043      0.965      0.335      -0.043       0.125
p+_lag4                      -0.0078      0.052     -0.148      0.882      -0.111       0.095
p-_lag4                      -0.0254      0.043     -0.597      0.551      -0.109       0.058
p+_lag5                      -0.0738      0.053     -1.389      0.166      -0.178       0.031
p-_lag5                      -0.0070      0.043     -0.162      0.872      -0.092       0.078
p+_lag6                      -0.1494      0.054     -2.752      0.006      -0.256      -0.043
p-_lag6                       0.0241      0.043      0.559      0.576      -0.061       0.109
p+_lag7                       0.0318      0.055      0.583      0.560      -0.076       0.139
p-_lag7                      -0.0136      0.043     -0.315      0.753      -0.099       0.071
p+_lag8                       0.0607      0.061      1.000      0.318      -0.059       0.180
p-_lag8                      -0.0778      0.044     -1.782      0.076      -0.164       0.008
p+_lag9                      -0.0621      0.060     -1.041      0.299      -0.179       0.055
p-_lag9                       0.0147      0.045      0.330      0.742      -0.073       0.102
p+_lag10                      0.0367      0.060      0.615      0.539      -0.081       0.154
p-_lag10                     -0.0326      0.054     -0.598      0.550      -0.140       0.075
p+_lag11                      0.1472      0.059      2.479      0.014       0.030       0.264
p-_lag11                      0.0354      0.054      0.650      0.516      -0.072       0.143
p+_lag12                      0.0293      0.060      0.487      0.627      -0.089       0.148
p-_lag12                      0.0646      0.054      1.194      0.233      -0.042       0.171
==============================================================================
Omnibus:                       20.053   Durbin-Watson:                   1.895
Prob(Omnibus):                  0.000   Jarque-Bera (JB):               57.629
Skew:                          -0.126   Prob(JB):                     3.06e-13
Kurtosis:                       5.019   Cond. No.                         6.30
==============================================================================

Warnings:
[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.
                            OLS Regression Results                            
==============================================================================
Dep. Variable:      Gasoline_Price_US   R-squared:                       0.484
Model:                            OLS   Adj. R-squared:                  0.389
Method:                 Least Squares   F-statistic:                     5.101
Date:                Sun, 28 Feb 2021   Prob (F-statistic):           5.91e-19
Time:                        15:24:57   Log-Likelihood:                 517.64
No. Observations:                 322   AIC:                            -935.3
Df Residuals:                     272   BIC:                            -746.5
Df Model:                          50                                         
Covariance Type:            nonrobust                                         
=============================================================================================
                                coef    std err          t      P>|t|      [0.025      0.975]
---------------------------------------------------------------------------------------------
chg_oil_spot_WTI_Positive     0.3123      0.058      5.373      0.000       0.198       0.427
chg_oil_spot_WTI_Negative     0.2541      0.039      6.483      0.000       0.177       0.331
p+_lag1                       0.2098      0.058      3.633      0.000       0.096       0.323
p-_lag1                       0.2105      0.039      5.338      0.000       0.133       0.288
p+_lag2                       0.0418      0.058      0.717      0.474      -0.073       0.156
p-_lag2                       0.0748      0.046      1.620      0.106      -0.016       0.166
p+_lag3                       0.0278      0.058      0.475      0.635      -0.087       0.143
p-_lag3                       0.0282      0.046      0.614      0.540      -0.062       0.119
p+_lag4                      -0.0082      0.058     -0.140      0.889      -0.123       0.107
p-_lag4                      -0.0368      0.046     -0.805      0.422      -0.127       0.053
p+_lag5                      -0.0738      0.059     -1.247      0.214      -0.190       0.043
p-_lag5                       0.0043      0.047      0.091      0.927      -0.087       0.096
p+_lag6                      -0.1627      0.060     -2.713      0.007      -0.281      -0.045
p-_lag6                       0.0178      0.047      0.383      0.702      -0.074       0.109
p+_lag7                       0.0310      0.060      0.517      0.606      -0.087       0.149
p-_lag7                      -0.0134      0.047     -0.286      0.775      -0.106       0.079
p+_lag8                       0.0586      0.069      0.855      0.394      -0.076       0.194
p-_lag8                      -0.0774      0.047     -1.636      0.103      -0.171       0.016
p+_lag9                      -0.0608      0.069     -0.886      0.376      -0.196       0.074
p-_lag9                       0.0104      0.048      0.217      0.829      -0.084       0.105
p+_lag10                      0.0099      0.069      0.144      0.886      -0.126       0.145
p-_lag10                     -0.0022      0.060     -0.036      0.971      -0.120       0.116
p+_lag11                      0.1169      0.069      1.687      0.093      -0.020       0.253
p-_lag11                      0.0389      0.060      0.646      0.519      -0.080       0.157
p+_lag12                      0.0051      0.070      0.073      0.942      -0.133       0.143
p-_lag12                      0.0656      0.061      1.084      0.279      -0.054       0.185
p+_lag13                     -0.0093      0.071     -0.131      0.896      -0.149       0.130
p-_lag13                     -0.0341      0.061     -0.560      0.576      -0.154       0.086
p+_lag14                      0.0572      0.071      0.805      0.422      -0.083       0.197
p-_lag14                     -0.0161      0.061     -0.264      0.792      -0.136       0.104
p+_lag15                      0.0923      0.071      1.292      0.198      -0.048       0.233
p-_lag15                     -0.0305      0.061     -0.500      0.618      -0.151       0.090
p+_lag16                     -0.0894      0.072     -1.244      0.215      -0.231       0.052
p-_lag16                     -0.0023      0.062     -0.038      0.970      -0.123       0.119
p+_lag17                      0.0439      0.072      0.609      0.543      -0.098       0.186
p-_lag17                     -0.0686      0.061     -1.119      0.264      -0.189       0.052
p+_lag18                     -0.0003      0.072     -0.005      0.996      -0.142       0.141
p-_lag18                      0.0472      0.062      0.760      0.448      -0.075       0.169
p+_lag19                     -0.1171      0.072     -1.632      0.104      -0.258       0.024
p-_lag19                      0.0701      0.062      1.128      0.260      -0.052       0.193
p+_lag20                     -0.1210      0.069     -1.759      0.080      -0.256       0.014
p-_lag20                      0.0870      0.062      1.404      0.161      -0.035       0.209
p+_lag21                      0.0141      0.068      0.206      0.837      -0.120       0.148
p-_lag21                     -0.0376      0.062     -0.608      0.544      -0.159       0.084
p+_lag22                      0.1004      0.068      1.486      0.138      -0.033       0.233
p-_lag22                     -0.0334      0.062     -0.540      0.590      -0.155       0.088
p+_lag23                      0.0327      0.067      0.485      0.628      -0.100       0.165
p-_lag23                     -0.0457      0.063     -0.730      0.466      -0.169       0.078
p+_lag24                     -0.0030      0.067     -0.046      0.964      -0.134       0.128
p-_lag24                     -0.0253      0.062     -0.409      0.683      -0.147       0.096
==============================================================================
Omnibus:                       15.769   Durbin-Watson:                   1.901
Prob(Omnibus):                  0.000   Jarque-Bera (JB):               40.484
Skew:                          -0.041   Prob(JB):                     1.62e-09
Kurtosis:                       4.735   Cond. No.                         10.2
==============================================================================

Warnings:
[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.
In [177]:
### Monthly CO2 ###
### Monthly Lag 0###

analysis = oil_co2_df.copy()
oil_co2_df.columns

analysis_month = analysis.groupby('Par_Month').last()[['oil_spot_WTI','Gasoline_Price_US','co2_conc']]

analysis_reg_month = np.log(analysis_month) - np.log(analysis_month.shift(1))
analysis_reg_month.dropna(inplace = True)
analysis_reg_month['co2_conc'] = analysis_reg_month['co2_conc'] - analysis_reg_month['co2_conc'].shift(12)
analysis_reg_month.dropna(inplace = True)

analysis_reg_month_edited = analysis_reg_month.copy()

analysis_reg_month_edited['chg_oil_spot_WTI_Positive'] = list(map(lambda x : 0 if x <= 0 else x,analysis_reg_month['oil_spot_WTI'] ))
analysis_reg_month_edited['chg_oil_spot_WTI_Negative'] = list(map(lambda x : 0 if x >= 0 else x,analysis_reg_month['oil_spot_WTI'] ))

analysis_reg = analysis_reg_month_edited.copy()

x = analysis_reg[['chg_oil_spot_WTI_Positive', 'chg_oil_spot_WTI_Negative']] 

reg_model = sm.OLS(analysis_reg['co2_conc'],x)
result = reg_model.fit()
print(result.summary())

### Monthly ###
### Monthly Lag 3###

analysis = oil_co2_df.copy()
oil_co2_df.columns

analysis_month = analysis.groupby('Par_Month').last()[['oil_spot_WTI','Gasoline_Price_US','co2_conc']]

analysis_reg_month = np.log(analysis_month) - np.log(analysis_month.shift(1))
analysis_reg_month.dropna(inplace = True)
analysis_reg_month['co2_conc'] = analysis_reg_month['co2_conc'] - analysis_reg_month['co2_conc'].shift(12)
analysis_reg_month.dropna(inplace = True)

analysis_reg_month_edited = analysis_reg_month.copy()

analysis_reg_month_edited['chg_oil_spot_WTI_Positive'] = list(map(lambda x : 0 if x <= 0 else x,analysis_reg_month['oil_spot_WTI'] ))
analysis_reg_month_edited['chg_oil_spot_WTI_Negative'] = list(map(lambda x : 0 if x >= 0 else x,analysis_reg_month['oil_spot_WTI'] ))

analysis_reg = analysis_reg_month_edited.copy()


analysis_reg['p+_lag1'] = analysis_reg_month_edited['chg_oil_spot_WTI_Positive'].shift(1)
analysis_reg['p+_lag2'] = analysis_reg_month_edited['chg_oil_spot_WTI_Positive'].shift(2)
analysis_reg['p+_lag3'] = analysis_reg_month_edited['chg_oil_spot_WTI_Positive'].shift(3)


analysis_reg['p-_lag1'] = analysis_reg_month_edited['chg_oil_spot_WTI_Negative'].shift(1)
analysis_reg['p-_lag2'] = analysis_reg_month_edited['chg_oil_spot_WTI_Negative'].shift(2)
analysis_reg['p-_lag3'] = analysis_reg_month_edited['chg_oil_spot_WTI_Negative'].shift(3)


analysis_reg = analysis_reg.dropna(subset = ['p+_lag1','p-_lag1','p+_lag2','p-_lag2','p+_lag3','p-_lag3'])

x = analysis_reg[['chg_oil_spot_WTI_Positive', 'chg_oil_spot_WTI_Negative','p+_lag1','p-_lag1','p+_lag2','p-_lag2','p+_lag3','p-_lag3']] 

reg_model = sm.OLS(analysis_reg['co2_conc'],x)
result = reg_model.fit()
print(result.summary())


### Monthly ###
### Monthly Lag 6###

analysis = oil_co2_df.copy()
oil_co2_df.columns

analysis_month = analysis.groupby('Par_Month').last()[['oil_spot_WTI','Gasoline_Price_US','co2_conc']]

analysis_reg_month = np.log(analysis_month) - np.log(analysis_month.shift(1))
analysis_reg_month.dropna(inplace = True)
analysis_reg_month['co2_conc'] = analysis_reg_month['co2_conc'] - analysis_reg_month['co2_conc'].shift(12)
analysis_reg_month.dropna(inplace = True)

analysis_reg_month_edited = analysis_reg_month.copy()

analysis_reg_month_edited['chg_oil_spot_WTI_Positive'] = list(map(lambda x : 0 if x <= 0 else x,analysis_reg_month['oil_spot_WTI'] ))
analysis_reg_month_edited['chg_oil_spot_WTI_Negative'] = list(map(lambda x : 0 if x >= 0 else x,analysis_reg_month['oil_spot_WTI'] ))

analysis_reg = analysis_reg_month_edited.copy()


analysis_reg['p+_lag1'] = analysis_reg_month_edited['chg_oil_spot_WTI_Positive'].shift(1)
analysis_reg['p+_lag2'] = analysis_reg_month_edited['chg_oil_spot_WTI_Positive'].shift(2)
analysis_reg['p+_lag3'] = analysis_reg_month_edited['chg_oil_spot_WTI_Positive'].shift(3)
analysis_reg['p+_lag4'] = analysis_reg_month_edited['chg_oil_spot_WTI_Positive'].shift(4)
analysis_reg['p+_lag5'] = analysis_reg_month_edited['chg_oil_spot_WTI_Positive'].shift(5)
analysis_reg['p+_lag6'] = analysis_reg_month_edited['chg_oil_spot_WTI_Positive'].shift(6)

analysis_reg['p-_lag1'] = analysis_reg_month_edited['chg_oil_spot_WTI_Negative'].shift(1)
analysis_reg['p-_lag2'] = analysis_reg_month_edited['chg_oil_spot_WTI_Negative'].shift(2)
analysis_reg['p-_lag3'] = analysis_reg_month_edited['chg_oil_spot_WTI_Negative'].shift(3)
analysis_reg['p-_lag4'] = analysis_reg_month_edited['chg_oil_spot_WTI_Negative'].shift(4)
analysis_reg['p-_lag5'] = analysis_reg_month_edited['chg_oil_spot_WTI_Negative'].shift(5)
analysis_reg['p-_lag6'] = analysis_reg_month_edited['chg_oil_spot_WTI_Negative'].shift(6)


analysis_reg = analysis_reg.dropna(subset = ['p+_lag1','p-_lag1','p+_lag2','p-_lag2','p+_lag3','p-_lag3','p+_lag4','p-_lag4','p+_lag5','p-_lag5','p+_lag6','p-_lag6'])

x = analysis_reg[['chg_oil_spot_WTI_Positive', 'chg_oil_spot_WTI_Negative','p+_lag1','p-_lag1','p+_lag2','p-_lag2','p+_lag3','p-_lag3','p+_lag4','p-_lag4','p+_lag5','p-_lag5','p+_lag6','p-_lag6']] 

reg_model = sm.OLS(analysis_reg['co2_conc'],x)
result = reg_model.fit()
print(result.summary())


### Monthly ###
### Monthly Lag 12###

analysis = oil_co2_df.copy()
oil_co2_df.columns

analysis_month = analysis.groupby('Par_Month').last()[['oil_spot_WTI','Gasoline_Price_US','co2_conc']]

analysis_reg_month = np.log(analysis_month) - np.log(analysis_month.shift(1))
analysis_reg_month.dropna(inplace = True)
analysis_reg_month['co2_conc'] = analysis_reg_month['co2_conc'] - analysis_reg_month['co2_conc'].shift(12)
analysis_reg_month.dropna(inplace = True)

analysis_reg_month_edited = analysis_reg_month.copy()

analysis_reg_month_edited['chg_oil_spot_WTI_Positive'] = list(map(lambda x : 0 if x <= 0 else x,analysis_reg_month['oil_spot_WTI'] ))
analysis_reg_month_edited['chg_oil_spot_WTI_Negative'] = list(map(lambda x : 0 if x >= 0 else x,analysis_reg_month['oil_spot_WTI'] ))

analysis_reg = analysis_reg_month_edited.copy()

analysis_reg['p+_lag1'] = analysis_reg_month_edited['chg_oil_spot_WTI_Positive'].shift(1)
analysis_reg['p+_lag2'] = analysis_reg_month_edited['chg_oil_spot_WTI_Positive'].shift(2)
analysis_reg['p+_lag3'] = analysis_reg_month_edited['chg_oil_spot_WTI_Positive'].shift(3)
analysis_reg['p+_lag4'] = analysis_reg_month_edited['chg_oil_spot_WTI_Positive'].shift(4)
analysis_reg['p+_lag5'] = analysis_reg_month_edited['chg_oil_spot_WTI_Positive'].shift(5)
analysis_reg['p+_lag6'] = analysis_reg_month_edited['chg_oil_spot_WTI_Positive'].shift(6)
analysis_reg['p+_lag7'] = analysis_reg_month_edited['chg_oil_spot_WTI_Positive'].shift(7)
analysis_reg['p+_lag8'] = analysis_reg_month_edited['chg_oil_spot_WTI_Positive'].shift(8)
analysis_reg['p+_lag9'] = analysis_reg_month_edited['chg_oil_spot_WTI_Positive'].shift(9)
analysis_reg['p+_lag10'] = analysis_reg_month_edited['chg_oil_spot_WTI_Positive'].shift(10)
analysis_reg['p+_lag11'] = analysis_reg_month_edited['chg_oil_spot_WTI_Positive'].shift(11)
analysis_reg['p+_lag12'] = analysis_reg_month_edited['chg_oil_spot_WTI_Positive'].shift(12)

analysis_reg['p-_lag1'] = analysis_reg_month_edited['chg_oil_spot_WTI_Negative'].shift(1)
analysis_reg['p-_lag2'] = analysis_reg_month_edited['chg_oil_spot_WTI_Negative'].shift(2)
analysis_reg['p-_lag3'] = analysis_reg_month_edited['chg_oil_spot_WTI_Negative'].shift(3)
analysis_reg['p-_lag4'] = analysis_reg_month_edited['chg_oil_spot_WTI_Negative'].shift(4)
analysis_reg['p-_lag5'] = analysis_reg_month_edited['chg_oil_spot_WTI_Negative'].shift(5)
analysis_reg['p-_lag6'] = analysis_reg_month_edited['chg_oil_spot_WTI_Negative'].shift(6)
analysis_reg['p-_lag7'] = analysis_reg_month_edited['chg_oil_spot_WTI_Negative'].shift(7)
analysis_reg['p-_lag8'] = analysis_reg_month_edited['chg_oil_spot_WTI_Negative'].shift(8)
analysis_reg['p-_lag9'] = analysis_reg_month_edited['chg_oil_spot_WTI_Negative'].shift(9)
analysis_reg['p-_lag10'] = analysis_reg_month_edited['chg_oil_spot_WTI_Negative'].shift(10)
analysis_reg['p-_lag11'] = analysis_reg_month_edited['chg_oil_spot_WTI_Negative'].shift(11)
analysis_reg['p-_lag12'] = analysis_reg_month_edited['chg_oil_spot_WTI_Negative'].shift(12)


analysis_reg = analysis_reg.dropna(subset = ['p+_lag1','p-_lag1','p+_lag2','p-_lag2','p+_lag3','p-_lag3','p+_lag4','p-_lag4','p+_lag5','p-_lag5','p+_lag6','p-_lag6','p+_lag7','p-_lag7','p+_lag8','p-_lag8','p+_lag9','p-_lag9','p+_lag10','p-_lag10','p+_lag11','p-_lag11','p+_lag12','p-_lag12'])

x = analysis_reg[['chg_oil_spot_WTI_Positive', 'chg_oil_spot_WTI_Negative','p+_lag1','p-_lag1','p+_lag2','p-_lag2','p+_lag3','p-_lag3','p+_lag4','p-_lag4','p+_lag5','p-_lag5','p+_lag6','p-_lag6','p+_lag7','p-_lag7','p+_lag8','p-_lag8','p+_lag9','p-_lag9','p+_lag10','p-_lag10','p+_lag11','p-_lag11','p+_lag12','p-_lag12']] 

reg_model = sm.OLS(analysis_reg['co2_conc'],x)
result = reg_model.fit()
print(result.summary())


### Monthly ###
### Monthly Lag 24###

analysis = oil_co2_df.copy()
oil_co2_df.columns

analysis_month = analysis.groupby('Par_Month').last()[['oil_spot_WTI','Gasoline_Price_US','co2_conc']]

analysis_reg_month = np.log(analysis_month) - np.log(analysis_month.shift(1))
analysis_reg_month.dropna(inplace = True)
analysis_reg_month['co2_conc'] = analysis_reg_month['co2_conc'] - analysis_reg_month['co2_conc'].shift(12)
analysis_reg_month.dropna(inplace = True)

analysis_reg_month_edited = analysis_reg_month.copy()

analysis_reg_month_edited['chg_oil_spot_WTI_Positive'] = list(map(lambda x : 0 if x <= 0 else x,analysis_reg_month['oil_spot_WTI'] ))
analysis_reg_month_edited['chg_oil_spot_WTI_Negative'] = list(map(lambda x : 0 if x >= 0 else x,analysis_reg_month['oil_spot_WTI'] ))

analysis_reg = analysis_reg_month_edited.copy()

analysis_reg = analysis_reg_month_edited.copy()
analysis_reg['p+_lag1'] = analysis_reg_month_edited['chg_oil_spot_WTI_Positive'].shift(1)
analysis_reg['p+_lag2'] = analysis_reg_month_edited['chg_oil_spot_WTI_Positive'].shift(2)
analysis_reg['p+_lag3'] = analysis_reg_month_edited['chg_oil_spot_WTI_Positive'].shift(3)
analysis_reg['p+_lag4'] = analysis_reg_month_edited['chg_oil_spot_WTI_Positive'].shift(4)
analysis_reg['p+_lag5'] = analysis_reg_month_edited['chg_oil_spot_WTI_Positive'].shift(5)
analysis_reg['p+_lag6'] = analysis_reg_month_edited['chg_oil_spot_WTI_Positive'].shift(6)
analysis_reg['p+_lag7'] = analysis_reg_month_edited['chg_oil_spot_WTI_Positive'].shift(7)
analysis_reg['p+_lag8'] = analysis_reg_month_edited['chg_oil_spot_WTI_Positive'].shift(8)
analysis_reg['p+_lag9'] = analysis_reg_month_edited['chg_oil_spot_WTI_Positive'].shift(9)
analysis_reg['p+_lag10'] = analysis_reg_month_edited['chg_oil_spot_WTI_Positive'].shift(10)
analysis_reg['p+_lag11'] = analysis_reg_month_edited['chg_oil_spot_WTI_Positive'].shift(11)
analysis_reg['p+_lag12'] = analysis_reg_month_edited['chg_oil_spot_WTI_Positive'].shift(12)
analysis_reg['p+_lag13'] = analysis_reg_month_edited['chg_oil_spot_WTI_Positive'].shift(13)
analysis_reg['p+_lag14'] = analysis_reg_month_edited['chg_oil_spot_WTI_Positive'].shift(14)
analysis_reg['p+_lag15'] = analysis_reg_month_edited['chg_oil_spot_WTI_Positive'].shift(15)
analysis_reg['p+_lag16'] = analysis_reg_month_edited['chg_oil_spot_WTI_Positive'].shift(16)
analysis_reg['p+_lag17'] = analysis_reg_month_edited['chg_oil_spot_WTI_Positive'].shift(17)
analysis_reg['p+_lag18'] = analysis_reg_month_edited['chg_oil_spot_WTI_Positive'].shift(18)
analysis_reg['p+_lag19'] = analysis_reg_month_edited['chg_oil_spot_WTI_Positive'].shift(19)
analysis_reg['p+_lag20'] = analysis_reg_month_edited['chg_oil_spot_WTI_Positive'].shift(20)
analysis_reg['p+_lag21'] = analysis_reg_month_edited['chg_oil_spot_WTI_Positive'].shift(21)
analysis_reg['p+_lag22'] = analysis_reg_month_edited['chg_oil_spot_WTI_Positive'].shift(22)
analysis_reg['p+_lag23'] = analysis_reg_month_edited['chg_oil_spot_WTI_Positive'].shift(23)
analysis_reg['p+_lag24'] = analysis_reg_month_edited['chg_oil_spot_WTI_Positive'].shift(24)

analysis_reg['p-_lag1'] = analysis_reg_month_edited['chg_oil_spot_WTI_Negative'].shift(1)
analysis_reg['p-_lag2'] = analysis_reg_month_edited['chg_oil_spot_WTI_Negative'].shift(2)
analysis_reg['p-_lag3'] = analysis_reg_month_edited['chg_oil_spot_WTI_Negative'].shift(3)
analysis_reg['p-_lag4'] = analysis_reg_month_edited['chg_oil_spot_WTI_Negative'].shift(4)
analysis_reg['p-_lag5'] = analysis_reg_month_edited['chg_oil_spot_WTI_Negative'].shift(5)
analysis_reg['p-_lag6'] = analysis_reg_month_edited['chg_oil_spot_WTI_Negative'].shift(6)
analysis_reg['p-_lag7'] = analysis_reg_month_edited['chg_oil_spot_WTI_Negative'].shift(7)
analysis_reg['p-_lag8'] = analysis_reg_month_edited['chg_oil_spot_WTI_Negative'].shift(8)
analysis_reg['p-_lag9'] = analysis_reg_month_edited['chg_oil_spot_WTI_Negative'].shift(9)
analysis_reg['p-_lag10'] = analysis_reg_month_edited['chg_oil_spot_WTI_Negative'].shift(10)
analysis_reg['p-_lag11'] = analysis_reg_month_edited['chg_oil_spot_WTI_Negative'].shift(11)
analysis_reg['p-_lag12'] = analysis_reg_month_edited['chg_oil_spot_WTI_Negative'].shift(12)
analysis_reg['p-_lag13'] = analysis_reg_month_edited['chg_oil_spot_WTI_Negative'].shift(13)
analysis_reg['p-_lag14'] = analysis_reg_month_edited['chg_oil_spot_WTI_Negative'].shift(14)
analysis_reg['p-_lag15'] = analysis_reg_month_edited['chg_oil_spot_WTI_Negative'].shift(15)
analysis_reg['p-_lag16'] = analysis_reg_month_edited['chg_oil_spot_WTI_Negative'].shift(16)
analysis_reg['p-_lag17'] = analysis_reg_month_edited['chg_oil_spot_WTI_Negative'].shift(17)
analysis_reg['p-_lag18'] = analysis_reg_month_edited['chg_oil_spot_WTI_Negative'].shift(18)
analysis_reg['p-_lag19'] = analysis_reg_month_edited['chg_oil_spot_WTI_Negative'].shift(19)
analysis_reg['p-_lag20'] = analysis_reg_month_edited['chg_oil_spot_WTI_Negative'].shift(20)
analysis_reg['p-_lag21'] = analysis_reg_month_edited['chg_oil_spot_WTI_Negative'].shift(21)
analysis_reg['p-_lag22'] = analysis_reg_month_edited['chg_oil_spot_WTI_Negative'].shift(22)
analysis_reg['p-_lag23'] = analysis_reg_month_edited['chg_oil_spot_WTI_Negative'].shift(23)
analysis_reg['p-_lag24'] = analysis_reg_month_edited['chg_oil_spot_WTI_Negative'].shift(24)


analysis_reg = analysis_reg.dropna(subset = ['p+_lag1','p-_lag1','p+_lag2','p-_lag2','p+_lag3','p-_lag3','p+_lag4','p-_lag4','p+_lag5','p-_lag5','p+_lag6','p-_lag6','p+_lag7','p-_lag7','p+_lag8','p-_lag8','p+_lag9','p-_lag9','p+_lag10','p-_lag10','p+_lag11','p-_lag11','p+_lag12','p-_lag12'
                                             ,'p+_lag13','p-_lag13','p+_lag14','p-_lag14','p+_lag15','p-_lag15','p+_lag16','p-_lag16','p+_lag17','p-_lag17','p+_lag18','p-_lag18','p+_lag19','p-_lag19','p+_lag20','p-_lag20','p+_lag21','p-_lag21','p+_lag22','p-_lag22','p+_lag23','p-_lag23','p+_lag24','p-_lag24'])

x = analysis_reg[['chg_oil_spot_WTI_Positive', 'chg_oil_spot_WTI_Negative','p+_lag1','p-_lag1','p+_lag2','p-_lag2','p+_lag3','p-_lag3','p+_lag4','p-_lag4','p+_lag5','p-_lag5','p+_lag6','p-_lag6','p+_lag7','p-_lag7','p+_lag8','p-_lag8','p+_lag9','p-_lag9','p+_lag10','p-_lag10','p+_lag11','p-_lag11','p+_lag12','p-_lag12'
                                             ,'p+_lag13','p-_lag13','p+_lag14','p-_lag14','p+_lag15','p-_lag15','p+_lag16','p-_lag16','p+_lag17','p-_lag17','p+_lag18','p-_lag18','p+_lag19','p-_lag19','p+_lag20','p-_lag20','p+_lag21','p-_lag21','p+_lag22','p-_lag22','p+_lag23','p-_lag23','p+_lag24','p-_lag24']] 

reg_model = sm.OLS(analysis_reg['co2_conc'],x)
result = reg_model.fit()
print(result.summary())
                            OLS Regression Results                            
==============================================================================
Dep. Variable:               co2_conc   R-squared:                       0.003
Model:                            OLS   Adj. R-squared:                 -0.002
Method:                 Least Squares   F-statistic:                    0.5700
Date:                Sun, 28 Feb 2021   Prob (F-statistic):              0.566
Time:                        15:24:58   Log-Likelihood:                 1621.3
No. Observations:                 346   AIC:                            -3239.
Df Residuals:                     344   BIC:                            -3231.
Df Model:                           2                                         
Covariance Type:            nonrobust                                         
=============================================================================================
                                coef    std err          t      P>|t|      [0.025      0.975]
---------------------------------------------------------------------------------------------
chg_oil_spot_WTI_Positive     0.0007      0.002      0.469      0.639      -0.002       0.004
chg_oil_spot_WTI_Negative    -0.0013      0.001     -0.959      0.338      -0.004       0.001
==============================================================================
Omnibus:                        0.740   Durbin-Watson:                   2.946
Prob(Omnibus):                  0.691   Jarque-Bera (JB):                0.563
Skew:                           0.088   Prob(JB):                        0.755
Kurtosis:                       3.091   Cond. No.                         1.16
==============================================================================

Warnings:
[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.
                            OLS Regression Results                            
==============================================================================
Dep. Variable:               co2_conc   R-squared:                       0.029
Model:                            OLS   Adj. R-squared:                  0.006
Method:                 Least Squares   F-statistic:                     1.257
Date:                Sun, 28 Feb 2021   Prob (F-statistic):              0.265
Time:                        15:24:58   Log-Likelihood:                 1615.4
No. Observations:                 343   AIC:                            -3215.
Df Residuals:                     335   BIC:                            -3184.
Df Model:                           8                                         
Covariance Type:            nonrobust                                         
=============================================================================================
                                coef    std err          t      P>|t|      [0.025      0.975]
---------------------------------------------------------------------------------------------
chg_oil_spot_WTI_Positive     0.0001      0.002      0.072      0.943      -0.004       0.004
chg_oil_spot_WTI_Negative    -0.0012      0.001     -0.801      0.424      -0.004       0.002
p+_lag1                       0.0009      0.002      0.443      0.658      -0.003       0.005
p-_lag1                       0.0009      0.002      0.566      0.572      -0.002       0.004
p+_lag2                       0.0001      0.002      0.066      0.947      -0.003       0.004
p-_lag2                      -0.0026      0.002     -1.504      0.134      -0.006       0.001
p+_lag3                       0.0002      0.002      0.098      0.922      -0.003       0.004
p-_lag3                       0.0038      0.002      2.176      0.030       0.000       0.007
==============================================================================
Omnibus:                        0.831   Durbin-Watson:                   2.947
Prob(Omnibus):                  0.660   Jarque-Bera (JB):                0.879
Skew:                           0.117   Prob(JB):                        0.644
Kurtosis:                       2.918   Cond. No.                         3.13
==============================================================================

Warnings:
[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.
                            OLS Regression Results                            
==============================================================================
Dep. Variable:               co2_conc   R-squared:                       0.094
Model:                            OLS   Adj. R-squared:                  0.055
Method:                 Least Squares   F-statistic:                     2.404
Date:                Sun, 28 Feb 2021   Prob (F-statistic):            0.00328
Time:                        15:24:58   Log-Likelihood:                 1613.1
No. Observations:                 340   AIC:                            -3198.
Df Residuals:                     326   BIC:                            -3145.
Df Model:                          14                                         
Covariance Type:            nonrobust                                         
=============================================================================================
                                coef    std err          t      P>|t|      [0.025      0.975]
---------------------------------------------------------------------------------------------
chg_oil_spot_WTI_Positive     0.0008      0.002      0.364      0.716      -0.003       0.005
chg_oil_spot_WTI_Negative    -0.0016      0.001     -1.075      0.283      -0.004       0.001
p+_lag1                      -0.0002      0.002     -0.095      0.925      -0.004       0.004
p-_lag1                       0.0009      0.001      0.623      0.534      -0.002       0.004
p+_lag2                      -0.0019      0.002     -0.915      0.361      -0.006       0.002
p-_lag2                      -0.0014      0.002     -0.768      0.443      -0.005       0.002
p+_lag3                       0.0019      0.002      0.876      0.382      -0.002       0.006
p-_lag3                       0.0030      0.002      1.681      0.094      -0.001       0.006
p+_lag4                      -0.0036      0.002     -1.699      0.090      -0.008       0.001
p-_lag4                      -0.0036      0.002     -2.036      0.043      -0.007      -0.000
p+_lag5                      -0.0031      0.002     -1.731      0.084      -0.007       0.000
p-_lag5                       0.0040      0.002      2.316      0.021       0.001       0.007
p+_lag6                       0.0038      0.002      2.082      0.038       0.000       0.007
p-_lag6                      -0.0046      0.002     -2.655      0.008      -0.008      -0.001
==============================================================================
Omnibus:                        0.058   Durbin-Watson:                   2.921
Prob(Omnibus):                  0.972   Jarque-Bera (JB):                0.143
Skew:                           0.020   Prob(JB):                        0.931
Kurtosis:                       2.908   Cond. No.                         4.25
==============================================================================

Warnings:
[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.
                            OLS Regression Results                            
==============================================================================
Dep. Variable:               co2_conc   R-squared:                       0.113
Model:                            OLS   Adj. R-squared:                  0.038
Method:                 Least Squares   F-statistic:                     1.507
Date:                Sun, 28 Feb 2021   Prob (F-statistic):             0.0569
Time:                        15:24:58   Log-Likelihood:                 1588.2
No. Observations:                 334   AIC:                            -3124.
Df Residuals:                     308   BIC:                            -3025.
Df Model:                          26                                         
Covariance Type:            nonrobust                                         
=============================================================================================
                                coef    std err          t      P>|t|      [0.025      0.975]
---------------------------------------------------------------------------------------------
chg_oil_spot_WTI_Positive     0.0013      0.002      0.589      0.556      -0.003       0.006
chg_oil_spot_WTI_Negative    -0.0021      0.002     -1.382      0.168      -0.005       0.001
p+_lag1                       0.0005      0.002      0.246      0.806      -0.004       0.005
p-_lag1                       0.0008      0.002      0.524      0.601      -0.002       0.004
p+_lag2                      -0.0013      0.002     -0.595      0.552      -0.006       0.003
p-_lag2                      -0.0014      0.002     -0.752      0.453      -0.005       0.002
p+_lag3                       0.0021      0.002      0.945      0.345      -0.002       0.006
p-_lag3                       0.0033      0.002      1.804      0.072      -0.000       0.007
p+_lag4                      -0.0035      0.002     -1.563      0.119      -0.008       0.001
p-_lag4                      -0.0033      0.002     -1.844      0.066      -0.007       0.000
p+_lag5                      -0.0013      0.002     -0.562      0.575      -0.006       0.003
p-_lag5                       0.0035      0.002      1.901      0.058      -0.000       0.007
p+_lag6                       0.0045      0.002      1.950      0.052   -4.12e-05       0.009
p-_lag6                      -0.0048      0.002     -2.632      0.009      -0.008      -0.001
p+_lag7                      -0.0006      0.002     -0.258      0.796      -0.005       0.004
p-_lag7                       0.0018      0.002      0.960      0.338      -0.002       0.005
p+_lag8                      -0.0005      0.003     -0.184      0.854      -0.006       0.005
p-_lag8                       0.0005      0.002      0.257      0.797      -0.003       0.004
p+_lag9                      -0.0012      0.003     -0.482      0.630      -0.006       0.004
p-_lag9                       0.0009      0.002      0.450      0.653      -0.003       0.005
p+_lag10                      0.0021      0.003      0.821      0.412      -0.003       0.007
p-_lag10                      0.0015      0.002      0.668      0.505      -0.003       0.006
p+_lag11                      0.0016      0.003      0.623      0.534      -0.003       0.007
p-_lag11                     -0.0015      0.002     -0.651      0.516      -0.006       0.003
p+_lag12                     -0.0031      0.003     -1.227      0.221      -0.008       0.002
p-_lag12                      0.0019      0.002      0.843      0.400      -0.003       0.006
==============================================================================
Omnibus:                        0.136   Durbin-Watson:                   2.940
Prob(Omnibus):                  0.934   Jarque-Bera (JB):                0.242
Skew:                           0.032   Prob(JB):                        0.886
Kurtosis:                       2.885   Cond. No.                         6.30
==============================================================================

Warnings:
[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.
                            OLS Regression Results                            
==============================================================================
Dep. Variable:               co2_conc   R-squared:                       0.184
Model:                            OLS   Adj. R-squared:                  0.034
Method:                 Least Squares   F-statistic:                     1.228
Date:                Sun, 28 Feb 2021   Prob (F-statistic):              0.155
Time:                        15:24:58   Log-Likelihood:                 1542.9
No. Observations:                 322   AIC:                            -2986.
Df Residuals:                     272   BIC:                            -2797.
Df Model:                          50                                         
Covariance Type:            nonrobust                                         
=============================================================================================
                                coef    std err          t      P>|t|      [0.025      0.975]
---------------------------------------------------------------------------------------------
chg_oil_spot_WTI_Positive     0.0013      0.002      0.520      0.603      -0.003       0.006
chg_oil_spot_WTI_Negative    -0.0021      0.002     -1.322      0.187      -0.005       0.001
p+_lag1                      -0.0002      0.002     -0.100      0.920      -0.005       0.004
p-_lag1                       0.0011      0.002      0.672      0.502      -0.002       0.004
p+_lag2                      -0.0004      0.002     -0.152      0.879      -0.005       0.004
p-_lag2                      -0.0011      0.002     -0.557      0.578      -0.005       0.003
p+_lag3                       0.0019      0.002      0.796      0.427      -0.003       0.007
p-_lag3                       0.0031      0.002      1.635      0.103      -0.001       0.007
p+_lag4                      -0.0045      0.002     -1.873      0.062      -0.009       0.000
p-_lag4                      -0.0036      0.002     -1.878      0.061      -0.007       0.000
p+_lag5                      -0.0021      0.002     -0.846      0.398      -0.007       0.003
p-_lag5                       0.0033      0.002      1.710      0.088      -0.000       0.007
p+_lag6                       0.0055      0.002      2.211      0.028       0.001       0.010
p-_lag6                      -0.0051      0.002     -2.640      0.009      -0.009      -0.001
p+_lag7                      -0.0013      0.002     -0.539      0.590      -0.006       0.004
p-_lag7                       0.0021      0.002      1.065      0.288      -0.002       0.006
p+_lag8                      -0.0006      0.003     -0.204      0.839      -0.006       0.005
p-_lag8                       0.0007      0.002      0.371      0.711      -0.003       0.005
p+_lag9                      -0.0005      0.003     -0.160      0.873      -0.006       0.005
p-_lag9                       0.0004      0.002      0.181      0.857      -0.004       0.004
p+_lag10                      0.0003      0.003      0.092      0.927      -0.005       0.006
p-_lag10                      0.0012      0.002      0.494      0.622      -0.004       0.006
p+_lag11                      0.0022      0.003      0.772      0.441      -0.003       0.008
p-_lag11                     -0.0008      0.002     -0.313      0.754      -0.006       0.004
p+_lag12                     -0.0031      0.003     -1.062      0.289      -0.009       0.003
p-_lag12                      0.0017      0.003      0.691      0.490      -0.003       0.007
p+_lag13                     -0.0007      0.003     -0.254      0.800      -0.007       0.005
p-_lag13                     -0.0023      0.003     -0.930      0.353      -0.007       0.003
p+_lag14                      0.0015      0.003      0.503      0.615      -0.004       0.007
p-_lag14                   3.298e-05      0.003      0.013      0.990      -0.005       0.005
p+_lag15                      0.0010      0.003      0.322      0.748      -0.005       0.007
p-_lag15                     -0.0006      0.003     -0.228      0.820      -0.006       0.004
p+_lag16                   4.838e-05      0.003      0.016      0.987      -0.006       0.006
p-_lag16                      0.0008      0.003      0.297      0.767      -0.004       0.006
p+_lag17                  -5.108e-05      0.003     -0.017      0.986      -0.006       0.006
p-_lag17                     -0.0003      0.003     -0.136      0.892      -0.005       0.005
p+_lag18                     -0.0032      0.003     -1.063      0.289      -0.009       0.003
p-_lag18                      0.0008      0.003      0.324      0.746      -0.004       0.006
p+_lag19                      0.0008      0.003      0.282      0.778      -0.005       0.007
p-_lag19                     -0.0012      0.003     -0.475      0.635      -0.006       0.004
p+_lag20                     -0.0028      0.003     -0.988      0.324      -0.008       0.003
p-_lag20                      0.0028      0.003      1.100      0.272      -0.002       0.008
p+_lag21                      0.0046      0.003      1.636      0.103      -0.001       0.010
p-_lag21                      0.0012      0.003      0.450      0.653      -0.004       0.006
p+_lag22                     -0.0004      0.003     -0.155      0.877      -0.006       0.005
p-_lag22                     -0.0064      0.003     -2.511      0.013      -0.011      -0.001
p+_lag23                     -0.0013      0.003     -0.456      0.649      -0.007       0.004
p-_lag23                     -0.0002      0.003     -0.084      0.933      -0.005       0.005
p+_lag24                      0.0014      0.003      0.507      0.613      -0.004       0.007
p-_lag24                      0.0035      0.003      1.387      0.167      -0.001       0.009
==============================================================================
Omnibus:                        0.001   Durbin-Watson:                   3.001
Prob(Omnibus):                  1.000   Jarque-Bera (JB):                0.043
Skew:                          -0.001   Prob(JB):                        0.979
Kurtosis:                       2.943   Cond. No.                         10.2
==============================================================================

Warnings:
[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.
Quarterly
In [178]:
#Quarterly
analysis = oil_co2_df.copy()
oil_co2_df.columns

analysis_quarter = analysis.query('Month in [12,3,6,9]').groupby('Par_Month').last()[['oil_spot_WTI','Gasoline_Price_US','co2_conc']]
analysis_quarter
Out[178]:
oil_spot_WTI Gasoline_Price_US co2_conc
Par_Month
199103 19.63 1.047 358.34
199106 20.56 1.114 357.20
199109 22.42 1.097 351.66
199112 18.82 1.063 356.46
199203 19.19 1.015 357.96
... ... ... ...
201912 61.76 2.447 412.99
202003 15.48 2.007 415.75
202006 38.53 2.048 415.43
202009 40.06 2.078 411.06
202012 48.35 2.158 415.25

120 rows × 3 columns

In [179]:
analysis_reg_quarter = np.log(analysis_quarter) - np.log(analysis_quarter.shift(1))
analysis_reg_quarter.dropna(inplace = True)
analysis_reg_quarter['co2_conc'] = analysis_reg_quarter['co2_conc'] - analysis_reg_quarter['co2_conc'].shift(4)
analysis_reg_quarter.dropna(inplace = True)

### Quarterly ###
analysis_reg_quarter_edited = analysis_reg_quarter.copy()

analysis_reg_quarter_edited['positive_change'] = list(map(lambda x : 0 if x <= 0 else x,analysis_reg_quarter['oil_spot_WTI'] ))
analysis_reg_quarter_edited['negative_change'] = list(map(lambda x : 0 if x >= 0 else x,analysis_reg_quarter['oil_spot_WTI'] ))


analysis_reg_quarter_edited['p+_lag1'] = analysis_reg_quarter_edited['positive_change'].shift(1)
analysis_reg_quarter_edited['p+_lag2'] = analysis_reg_quarter_edited['positive_change'].shift(2)
analysis_reg_quarter_edited['p+_lag3'] = analysis_reg_quarter_edited['positive_change'].shift(3)
analysis_reg_quarter_edited['p+_lag4'] = analysis_reg_quarter_edited['positive_change'].shift(4)
analysis_reg_quarter_edited['p+_lag5'] = analysis_reg_quarter_edited['positive_change'].shift(5)
analysis_reg_quarter_edited['p+_lag6'] = analysis_reg_quarter_edited['positive_change'].shift(6)
analysis_reg_quarter_edited['p+_lag7'] = analysis_reg_quarter_edited['positive_change'].shift(7)
analysis_reg_quarter_edited['p+_lag8'] = analysis_reg_quarter_edited['positive_change'].shift(8)
analysis_reg_quarter_edited['p+_lag9'] = analysis_reg_quarter_edited['positive_change'].shift(9)
analysis_reg_quarter_edited['p+_lag10'] = analysis_reg_quarter_edited['positive_change'].shift(10)

analysis_reg_quarter_edited['p-_lag1'] = analysis_reg_quarter_edited['negative_change'].shift(1)
analysis_reg_quarter_edited['p-_lag2'] = analysis_reg_quarter_edited['negative_change'].shift(2)
analysis_reg_quarter_edited['p-_lag3'] = analysis_reg_quarter_edited['negative_change'].shift(3)
analysis_reg_quarter_edited['p-_lag4'] = analysis_reg_quarter_edited['negative_change'].shift(4)
analysis_reg_quarter_edited['p-_lag5'] = analysis_reg_quarter_edited['negative_change'].shift(5)
analysis_reg_quarter_edited['p-_lag6'] = analysis_reg_quarter_edited['negative_change'].shift(6)
analysis_reg_quarter_edited['p-_lag7'] = analysis_reg_quarter_edited['negative_change'].shift(7)
analysis_reg_quarter_edited['p-_lag8'] = analysis_reg_quarter_edited['negative_change'].shift(8)
analysis_reg_quarter_edited['p-_lag9'] = analysis_reg_quarter_edited['negative_change'].shift(9)
analysis_reg_quarter_edited['p-_lag10'] = analysis_reg_quarter_edited['negative_change'].shift(10)


analysis_reg_quarter_edited = analysis_reg_quarter_edited.dropna()
In [180]:
#Quarterly gas
x = analysis_reg_quarter_edited[['positive_change', 'negative_change','p+_lag1', 'p+_lag2',
       'p+_lag3', 'p+_lag4', 'p+_lag5', 'p+_lag6', 'p+_lag7', 'p+_lag8',
       'p+_lag9', 'p+_lag10', 'p-_lag1', 'p-_lag2', 'p-_lag3', 'p-_lag4',
       'p-_lag5', 'p-_lag6', 'p-_lag7', 'p-_lag8', 'p-_lag9', 'p-_lag10']] 

reg_model = sm.OLS(analysis_reg_quarter_edited['Gasoline_Price_US'],x)
result = reg_model.fit()
print(result.summary())
## Three years of emissions
                            OLS Regression Results                            
==============================================================================
Dep. Variable:      Gasoline_Price_US   R-squared:                       0.605
Model:                            OLS   Adj. R-squared:                  0.501
Method:                 Least Squares   F-statistic:                     5.789
Date:                Sun, 28 Feb 2021   Prob (F-statistic):           1.92e-09
Time:                        15:24:58   Log-Likelihood:                 106.00
No. Observations:                 105   AIC:                            -168.0
Df Residuals:                      83   BIC:                            -109.6
Df Model:                          22                                         
Covariance Type:            nonrobust                                         
===================================================================================
                      coef    std err          t      P>|t|      [0.025      0.975]
-----------------------------------------------------------------------------------
positive_change     0.3851      0.115      3.352      0.001       0.157       0.614
negative_change     0.4699      0.060      7.813      0.000       0.350       0.590
p+_lag1             0.0012      0.114      0.010      0.992      -0.225       0.227
p+_lag2            -0.1027      0.113     -0.909      0.366      -0.328       0.122
p+_lag3            -0.0130      0.124     -0.105      0.917      -0.260       0.234
p+_lag4             0.3456      0.134      2.588      0.011       0.080       0.611
p+_lag5            -0.0574      0.136     -0.421      0.674      -0.328       0.214
p+_lag6            -0.1682      0.145     -1.157      0.251      -0.458       0.121
p+_lag7             0.0470      0.148      0.317      0.752      -0.248       0.342
p+_lag8            -0.0262      0.146     -0.180      0.858      -0.316       0.264
p+_lag9             0.1543      0.130      1.191      0.237      -0.103       0.412
p+_lag10           -0.1332      0.127     -1.053      0.295      -0.385       0.118
p-_lag1             0.0939      0.076      1.228      0.223      -0.058       0.246
p-_lag2            -0.0536      0.077     -0.692      0.491      -0.207       0.100
p-_lag3            -0.0275      0.077     -0.357      0.722      -0.181       0.126
p-_lag4             0.0474      0.088      0.539      0.591      -0.127       0.222
p-_lag5            -0.1167      0.091     -1.282      0.203      -0.298       0.064
p-_lag6             0.1252      0.094      1.330      0.187      -0.062       0.312
p-_lag7            -0.0251      0.094     -0.267      0.790      -0.213       0.162
p-_lag8            -0.0340      0.097     -0.351      0.726      -0.226       0.158
p-_lag9             0.0039      0.097      0.041      0.968      -0.189       0.197
p-_lag10           -0.1144      0.096     -1.195      0.235      -0.305       0.076
==============================================================================
Omnibus:                       11.228   Durbin-Watson:                   2.879
Prob(Omnibus):                  0.004   Jarque-Bera (JB):               15.758
Skew:                          -0.516   Prob(JB):                     0.000379
Kurtosis:                       4.593   Cond. No.                         7.37
==============================================================================

Warnings:
[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.
In [181]:
result.tvalues.to_frame()
Out[181]:
0
positive_change 3.351839
negative_change 7.812903
p+_lag1 0.010260
p+_lag2 -0.908627
p+_lag3 -0.104785
p+_lag4 2.588076
p+_lag5 -0.421495
p+_lag6 -1.156638
p+_lag7 0.316868
p+_lag8 -0.179598
p+_lag9 1.191219
p+_lag10 -1.053027
p-_lag1 1.227961
p-_lag2 -0.692032
p-_lag3 -0.356536
p-_lag4 0.539282
p-_lag5 -1.282190
p-_lag6 1.329793
p-_lag7 -0.266762
p-_lag8 -0.351243
p-_lag9 0.040533
p-_lag10 -1.195242
In [182]:
#Quarterly oil futuress to future gasoline
#Quarterly
analysis = oil_co2_df.copy()
oil_co2_df.columns


analysis_quarter = analysis.query('Month in [12,3,6,9]').groupby('Par_Month').last()[['future_oil_contract_1','Gasoline_Price_US','co2_conc']]


analysis_reg_quarter = np.log(analysis_quarter) - np.log(analysis_quarter.shift(1))
analysis_reg_quarter.dropna(inplace = True)
analysis_reg_quarter['co2_conc'] = analysis_reg_quarter['co2_conc'] - analysis_reg_quarter['co2_conc'].shift(4)
analysis_reg_quarter.dropna(inplace = True)

### Quarterly ###
analysis_reg_quarter_edited = analysis_reg_quarter.copy()

analysis_reg_quarter_edited['positive_change'] = list(map(lambda x : 0 if x <= 0 else x,analysis_reg_quarter['future_oil_contract_1']))
analysis_reg_quarter_edited['negative_change'] = list(map(lambda x : 0 if x >= 0 else x,analysis_reg_quarter['future_oil_contract_1']))


analysis_reg_quarter_edited['p+_lag1'] = analysis_reg_quarter_edited['positive_change'].shift(1)
analysis_reg_quarter_edited['p+_lag2'] = analysis_reg_quarter_edited['positive_change'].shift(2)
analysis_reg_quarter_edited['p+_lag3'] = analysis_reg_quarter_edited['positive_change'].shift(3)
analysis_reg_quarter_edited['p+_lag4'] = analysis_reg_quarter_edited['positive_change'].shift(4)
analysis_reg_quarter_edited['p+_lag5'] = analysis_reg_quarter_edited['positive_change'].shift(5)
analysis_reg_quarter_edited['p+_lag6'] = analysis_reg_quarter_edited['positive_change'].shift(6)
analysis_reg_quarter_edited['p+_lag7'] = analysis_reg_quarter_edited['positive_change'].shift(7)
analysis_reg_quarter_edited['p+_lag8'] = analysis_reg_quarter_edited['positive_change'].shift(8)
analysis_reg_quarter_edited['p+_lag9'] = analysis_reg_quarter_edited['positive_change'].shift(9)
analysis_reg_quarter_edited['p+_lag10'] = analysis_reg_quarter_edited['positive_change'].shift(10)

analysis_reg_quarter_edited['chg_future_gasoline_lag-1'] = analysis_reg_quarter_edited['Gasoline_Price_US'].shift(-1)


analysis_reg_quarter_edited['p-_lag1'] = analysis_reg_quarter_edited['negative_change'].shift(1)
analysis_reg_quarter_edited['p-_lag2'] = analysis_reg_quarter_edited['negative_change'].shift(2)
analysis_reg_quarter_edited['p-_lag3'] = analysis_reg_quarter_edited['negative_change'].shift(3)
analysis_reg_quarter_edited['p-_lag4'] = analysis_reg_quarter_edited['negative_change'].shift(4)
analysis_reg_quarter_edited['p-_lag5'] = analysis_reg_quarter_edited['negative_change'].shift(5)
analysis_reg_quarter_edited['p-_lag6'] = analysis_reg_quarter_edited['negative_change'].shift(6)
analysis_reg_quarter_edited['p-_lag7'] = analysis_reg_quarter_edited['negative_change'].shift(7)
analysis_reg_quarter_edited['p-_lag8'] = analysis_reg_quarter_edited['negative_change'].shift(8)
analysis_reg_quarter_edited['p-_lag9'] = analysis_reg_quarter_edited['negative_change'].shift(9)
analysis_reg_quarter_edited['p-_lag10'] = analysis_reg_quarter_edited['negative_change'].shift(10)


analysis_reg_quarter_edited = analysis_reg_quarter_edited.dropna()
In [183]:
#Quarterly gas
x = analysis_reg_quarter_edited[['positive_change', 'negative_change','p+_lag1', 'p+_lag2',
       'p+_lag3', 'p+_lag4', 'p+_lag5', 'p+_lag6', 'p+_lag7', 'p+_lag8',
       'p+_lag9', 'p+_lag10', 'p-_lag1', 'p-_lag2', 'p-_lag3', 'p-_lag4',
       'p-_lag5', 'p-_lag6', 'p-_lag7', 'p-_lag8', 'p-_lag9', 'p-_lag10']] 

reg_model = sm.OLS(analysis_reg_quarter_edited['chg_future_gasoline_lag-1'],x)
result = reg_model.fit()
print(result.summary())
## Three years of emissions
                                OLS Regression Results                               
=====================================================================================
Dep. Variable:     chg_future_gasoline_lag-1   R-squared:                       0.133
Model:                                   OLS   Adj. R-squared:                 -0.100
Method:                        Least Squares   F-statistic:                    0.5716
Date:                       Sun, 28 Feb 2021   Prob (F-statistic):              0.931
Time:                               15:24:59   Log-Likelihood:                 63.704
No. Observations:                        104   AIC:                            -83.41
Df Residuals:                             82   BIC:                            -25.23
Df Model:                                 22                                         
Covariance Type:                   nonrobust                                         
===================================================================================
                      coef    std err          t      P>|t|      [0.025      0.975]
-----------------------------------------------------------------------------------
positive_change    -0.0167      0.191     -0.088      0.930      -0.396       0.362
negative_change    -0.0189      0.103     -0.185      0.854      -0.223       0.185
p+_lag1            -0.0673      0.190     -0.355      0.724      -0.444       0.310
p+_lag2             0.1206      0.197      0.612      0.542      -0.272       0.513
p+_lag3             0.0471      0.197      0.239      0.812      -0.346       0.440
p+_lag4            -0.2597      0.206     -1.260      0.211      -0.670       0.150
p+_lag5            -0.1674      0.222     -0.755      0.452      -0.608       0.273
p+_lag6             0.1111      0.225      0.494      0.622      -0.336       0.558
p+_lag7             0.1081      0.228      0.474      0.637      -0.346       0.562
p+_lag8             0.0548      0.226      0.243      0.809      -0.395       0.504
p+_lag9            -0.2739      0.197     -1.388      0.169      -0.666       0.119
p+_lag10            0.0113      0.192      0.059      0.953      -0.372       0.394
p-_lag1            -0.1708      0.119     -1.432      0.156      -0.408       0.067
p-_lag2            -0.0397      0.123     -0.324      0.747      -0.284       0.204
p-_lag3             0.0890      0.138      0.647      0.519      -0.185       0.363
p-_lag4             0.0088      0.140      0.063      0.950      -0.269       0.287
p-_lag5            -0.0823      0.140     -0.587      0.559      -0.361       0.196
p-_lag6            -0.0458      0.143     -0.319      0.750      -0.331       0.240
p-_lag7            -0.1826      0.145     -1.263      0.210      -0.470       0.105
p-_lag8             0.0164      0.153      0.107      0.915      -0.288       0.321
p-_lag9            -0.0487      0.148     -0.329      0.743      -0.344       0.246
p-_lag10           -0.0434      0.146     -0.297      0.767      -0.334       0.248
==============================================================================
Omnibus:                       67.249   Durbin-Watson:                   2.266
Prob(Omnibus):                  0.000   Jarque-Bera (JB):              472.027
Skew:                          -1.980   Prob(JB):                    3.17e-103
Kurtosis:                      12.657   Cond. No.                         7.43
==============================================================================

Warnings:
[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.
In [184]:
result.tvalues.to_frame()
Out[184]:
0
positive_change -0.087512
negative_change -0.184812
p+_lag1 -0.354786
p+_lag2 0.611837
p+_lag3 0.238629
p+_lag4 -1.260058
p+_lag5 -0.755333
p+_lag6 0.494390
p+_lag7 0.473759
p+_lag8 0.242560
p+_lag9 -1.388320
p+_lag10 0.058752
p-_lag1 -1.431799
p-_lag2 -0.323687
p-_lag3 0.646930
p-_lag4 0.062925
p-_lag5 -0.587350
p-_lag6 -0.319282
p-_lag7 -1.262583
p-_lag8 0.107426
p-_lag9 -0.328775
p-_lag10 -0.296674
In [185]:
#Quarterly CO2
x = analysis_reg_quarter_edited[['positive_change', 'negative_change','p+_lag1', 'p+_lag2',
       'p+_lag3', 'p+_lag4', 'p+_lag5', 'p+_lag6', 'p+_lag7', 'p+_lag8',
       'p+_lag9', 'p+_lag10', 'p-_lag1', 'p-_lag2', 'p-_lag3', 'p-_lag4',
       'p-_lag5', 'p-_lag6', 'p-_lag7', 'p-_lag8', 'p-_lag9', 'p-_lag10']] 

reg_model = sm.OLS(analysis_reg_quarter_edited['co2_conc'],x)
result = reg_model.fit()
print(result.summary())
## Three years of emissions
                            OLS Regression Results                            
==============================================================================
Dep. Variable:               co2_conc   R-squared:                       0.333
Model:                            OLS   Adj. R-squared:                  0.155
Method:                 Least Squares   F-statistic:                     1.864
Date:                Sun, 28 Feb 2021   Prob (F-statistic):             0.0231
Time:                        15:24:59   Log-Likelihood:                 513.25
No. Observations:                 104   AIC:                            -982.5
Df Residuals:                      82   BIC:                            -924.3
Df Model:                          22                                         
Covariance Type:            nonrobust                                         
===================================================================================
                      coef    std err          t      P>|t|      [0.025      0.975]
-----------------------------------------------------------------------------------
positive_change    -0.0013      0.003     -0.533      0.595      -0.006       0.004
negative_change    -0.0004      0.001     -0.324      0.747      -0.003       0.002
p+_lag1            -0.0014      0.003     -0.542      0.589      -0.006       0.004
p+_lag2            -0.0033      0.003     -1.274      0.206      -0.009       0.002
p+_lag3             0.0024      0.003      0.919      0.361      -0.003       0.008
p+_lag4             0.0005      0.003      0.165      0.869      -0.005       0.006
p+_lag5             0.0044      0.003      1.512      0.134      -0.001       0.010
p+_lag6             0.0024      0.003      0.821      0.414      -0.003       0.008
p+_lag7            -0.0044      0.003     -1.465      0.147      -0.010       0.002
p+_lag8             0.0020      0.003      0.668      0.506      -0.004       0.008
p+_lag9            -0.0020      0.003     -0.778      0.439      -0.007       0.003
p+_lag10            0.0015      0.003      0.577      0.565      -0.004       0.007
p-_lag1             0.0037      0.002      2.364      0.020       0.001       0.007
p-_lag2            -0.0049      0.002     -3.008      0.003      -0.008      -0.002
p-_lag3             0.0030      0.002      1.667      0.099      -0.001       0.007
p-_lag4            -0.0024      0.002     -1.293      0.200      -0.006       0.001
p-_lag5            -0.0021      0.002     -1.116      0.268      -0.006       0.002
p-_lag6             0.0004      0.002      0.200      0.842      -0.003       0.004
p-_lag7             0.0022      0.002      1.169      0.246      -0.002       0.006
p-_lag8             0.0019      0.002      0.933      0.354      -0.002       0.006
p-_lag9            -0.0002      0.002     -0.084      0.934      -0.004       0.004
p-_lag10           -0.0004      0.002     -0.211      0.833      -0.004       0.003
==============================================================================
Omnibus:                        1.013   Durbin-Watson:                   2.661
Prob(Omnibus):                  0.603   Jarque-Bera (JB):                1.037
Skew:                          -0.229   Prob(JB):                        0.595
Kurtosis:                       2.827   Cond. No.                         7.43
==============================================================================

Warnings:
[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.
In [186]:
result.tvalues.to_frame()
Out[186]:
0
positive_change -0.533131
negative_change -0.323646
p+_lag1 -0.542292
p+_lag2 -1.274141
p+_lag3 0.918910
p+_lag4 0.165203
p+_lag5 1.512058
p+_lag6 0.821328
p+_lag7 -1.465174
p+_lag8 0.667699
p+_lag9 -0.777765
p+_lag10 0.577202
p-_lag1 2.364268
p-_lag2 -3.008098
p-_lag3 1.666771
p-_lag4 -1.293013
p-_lag5 -1.116408
p-_lag6 0.199660
p-_lag7 1.168605
p-_lag8 0.932826
p-_lag9 -0.083516
p-_lag10 -0.211366
In [187]:
### Quarterly CO2 ###
### Quarterly Lag 0###

analysis = oil_co2_df.copy()
oil_co2_df.columns

analysis_quarter = analysis.query('Month in [12,3,6,9]').groupby('Par_Month').last()[['oil_spot_WTI','Gasoline_Price_US','co2_conc']]

analysis_reg_quarter = np.log(analysis_quarter) - np.log(analysis_quarter.shift(1))
analysis_reg_quarter.dropna(inplace = True)
analysis_reg_quarter['co2_conc'] = analysis_reg_quarter['co2_conc'] - analysis_reg_quarter['co2_conc'].shift(4)
analysis_reg_quarter.dropna(inplace = True)

### Quarterly ###
analysis_reg_quarter_edited = analysis_reg_quarter.copy()

analysis_reg_quarter_edited['chg_oil_spot_WTI_Positive'] = list(map(lambda x : 0 if x <= 0 else x,analysis_reg_quarter['oil_spot_WTI'] ))
analysis_reg_quarter_edited['chg_oil_spot_WTI_Negative'] = list(map(lambda x : 0 if x >= 0 else x,analysis_reg_quarter['oil_spot_WTI'] ))

analysis_reg = analysis_reg_quarter_edited.copy()

x = analysis_reg[['chg_oil_spot_WTI_Positive', 'chg_oil_spot_WTI_Negative']] 

reg_model = sm.OLS(analysis_reg['Gasoline_Price_US'],x)
result = reg_model.fit()
print(result.summary())

### Quarterly ###
### Quarterly Lag 3###

analysis = oil_co2_df.copy()
oil_co2_df.columns

analysis_quarter = analysis.query('Month in [12,3,6,9]').groupby('Par_Month').last()[['oil_spot_WTI','Gasoline_Price_US','co2_conc']]

analysis_reg_quarter = np.log(analysis_quarter) - np.log(analysis_quarter.shift(1))
analysis_reg_quarter.dropna(inplace = True)
analysis_reg_quarter['co2_conc'] = analysis_reg_quarter['co2_conc'] - analysis_reg_quarter['co2_conc'].shift(4)
analysis_reg_quarter.dropna(inplace = True)

### Quarterly ###
analysis_reg_quarter_edited = analysis_reg_quarter.copy()

analysis_reg_quarter_edited['chg_oil_spot_WTI_Positive'] = list(map(lambda x : 0 if x <= 0 else x,analysis_reg_quarter['oil_spot_WTI'] ))
analysis_reg_quarter_edited['chg_oil_spot_WTI_Negative'] = list(map(lambda x : 0 if x >= 0 else x,analysis_reg_quarter['oil_spot_WTI'] ))

analysis_reg = analysis_reg_quarter_edited.copy()


analysis_reg['p+_lag1'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Positive'].shift(1)
analysis_reg['p+_lag2'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Positive'].shift(2)
analysis_reg['p+_lag3'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Positive'].shift(3)


analysis_reg['p-_lag1'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Negative'].shift(1)
analysis_reg['p-_lag2'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Negative'].shift(2)
analysis_reg['p-_lag3'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Negative'].shift(3)


analysis_reg = analysis_reg.dropna(subset = ['p+_lag1','p-_lag1','p+_lag2','p-_lag2','p+_lag3','p-_lag3'])

x = analysis_reg[['chg_oil_spot_WTI_Positive', 'chg_oil_spot_WTI_Negative','p+_lag1','p-_lag1','p+_lag2','p-_lag2','p+_lag3','p-_lag3']] 

reg_model = sm.OLS(analysis_reg['Gasoline_Price_US'],x)
result = reg_model.fit()
print(result.summary())


### Quarterly ###
### Quarterly Lag 6###

analysis = oil_co2_df.copy()
oil_co2_df.columns

analysis = oil_co2_df.copy()
oil_co2_df.columns

analysis_quarter = analysis.query('Month in [12,3,6,9]').groupby('Par_Month').last()[['oil_spot_WTI','Gasoline_Price_US','co2_conc']]

analysis_reg_quarter = np.log(analysis_quarter) - np.log(analysis_quarter.shift(1))
analysis_reg_quarter.dropna(inplace = True)
analysis_reg_quarter['co2_conc'] = analysis_reg_quarter['co2_conc'] - analysis_reg_quarter['co2_conc'].shift(4)
analysis_reg_quarter.dropna(inplace = True)

### Quarterly ###
analysis_reg_quarter_edited = analysis_reg_quarter.copy()

analysis_reg_quarter_edited['chg_oil_spot_WTI_Positive'] = list(map(lambda x : 0 if x <= 0 else x,analysis_reg_quarter['oil_spot_WTI'] ))
analysis_reg_quarter_edited['chg_oil_spot_WTI_Negative'] = list(map(lambda x : 0 if x >= 0 else x,analysis_reg_quarter['oil_spot_WTI'] ))

analysis_reg = analysis_reg_quarter_edited.copy()

analysis_reg['p+_lag1'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Positive'].shift(1)
analysis_reg['p+_lag2'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Positive'].shift(2)
analysis_reg['p+_lag3'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Positive'].shift(3)
analysis_reg['p+_lag4'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Positive'].shift(4)
analysis_reg['p+_lag5'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Positive'].shift(5)
analysis_reg['p+_lag6'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Positive'].shift(6)

analysis_reg['p-_lag1'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Negative'].shift(1)
analysis_reg['p-_lag2'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Negative'].shift(2)
analysis_reg['p-_lag3'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Negative'].shift(3)
analysis_reg['p-_lag4'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Negative'].shift(4)
analysis_reg['p-_lag5'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Negative'].shift(5)
analysis_reg['p-_lag6'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Negative'].shift(6)


analysis_reg = analysis_reg.dropna(subset = ['p+_lag1','p-_lag1','p+_lag2','p-_lag2','p+_lag3','p-_lag3','p+_lag4','p-_lag4','p+_lag5','p-_lag5','p+_lag6','p-_lag6'])

x = analysis_reg[['chg_oil_spot_WTI_Positive', 'chg_oil_spot_WTI_Negative','p+_lag1','p-_lag1','p+_lag2','p-_lag2','p+_lag3','p-_lag3','p+_lag4','p-_lag4','p+_lag5','p-_lag5','p+_lag6','p-_lag6']] 

reg_model = sm.OLS(analysis_reg['Gasoline_Price_US'],x)
result = reg_model.fit()
print(result.summary())


### quarterly ###
### Quarterly Lag 12###

analysis = oil_co2_df.copy()
oil_co2_df.columns

analysis_quarter = analysis.query('Month in [12,3,6,9]').groupby('Par_Month').last()[['oil_spot_WTI','Gasoline_Price_US','co2_conc']]

analysis_reg_quarter = np.log(analysis_quarter) - np.log(analysis_quarter.shift(1))
analysis_reg_quarter.dropna(inplace = True)
analysis_reg_quarter['co2_conc'] = analysis_reg_quarter['co2_conc'] - analysis_reg_quarter['co2_conc'].shift(4)
analysis_reg_quarter.dropna(inplace = True)

### Quarterly ###
analysis_reg_quarter_edited = analysis_reg_quarter.copy()

analysis_reg_quarter_edited['chg_oil_spot_WTI_Positive'] = list(map(lambda x : 0 if x <= 0 else x,analysis_reg_quarter['oil_spot_WTI'] ))
analysis_reg_quarter_edited['chg_oil_spot_WTI_Negative'] = list(map(lambda x : 0 if x >= 0 else x,analysis_reg_quarter['oil_spot_WTI'] ))

analysis_reg = analysis_reg_quarter_edited.copy()

analysis_reg['p+_lag1'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Positive'].shift(1)
analysis_reg['p+_lag2'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Positive'].shift(2)
analysis_reg['p+_lag3'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Positive'].shift(3)
analysis_reg['p+_lag4'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Positive'].shift(4)
analysis_reg['p+_lag5'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Positive'].shift(5)
analysis_reg['p+_lag6'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Positive'].shift(6)
analysis_reg['p+_lag7'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Positive'].shift(7)
analysis_reg['p+_lag8'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Positive'].shift(8)
analysis_reg['p+_lag9'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Positive'].shift(9)
analysis_reg['p+_lag10'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Positive'].shift(10)
analysis_reg['p+_lag11'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Positive'].shift(11)
analysis_reg['p+_lag12'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Positive'].shift(12)

analysis_reg['p-_lag1'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Negative'].shift(1)
analysis_reg['p-_lag2'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Negative'].shift(2)
analysis_reg['p-_lag3'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Negative'].shift(3)
analysis_reg['p-_lag4'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Negative'].shift(4)
analysis_reg['p-_lag5'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Negative'].shift(5)
analysis_reg['p-_lag6'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Negative'].shift(6)
analysis_reg['p-_lag7'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Negative'].shift(7)
analysis_reg['p-_lag8'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Negative'].shift(8)
analysis_reg['p-_lag9'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Negative'].shift(9)
analysis_reg['p-_lag10'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Negative'].shift(10)
analysis_reg['p-_lag11'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Negative'].shift(11)
analysis_reg['p-_lag12'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Negative'].shift(12)


analysis_reg = analysis_reg.dropna(subset = ['p+_lag1','p-_lag1','p+_lag2','p-_lag2','p+_lag3','p-_lag3','p+_lag4','p-_lag4','p+_lag5','p-_lag5','p+_lag6','p-_lag6','p+_lag7','p-_lag7','p+_lag8','p-_lag8','p+_lag9','p-_lag9','p+_lag10','p-_lag10','p+_lag11','p-_lag11','p+_lag12','p-_lag12'])

x = analysis_reg[['chg_oil_spot_WTI_Positive', 'chg_oil_spot_WTI_Negative','p+_lag1','p-_lag1','p+_lag2','p-_lag2','p+_lag3','p-_lag3','p+_lag4','p-_lag4','p+_lag5','p-_lag5','p+_lag6','p-_lag6','p+_lag7','p-_lag7','p+_lag8','p-_lag8','p+_lag9','p-_lag9','p+_lag10','p-_lag10','p+_lag11','p-_lag11','p+_lag12','p-_lag12']] 

reg_model = sm.OLS(analysis_reg['Gasoline_Price_US'],x)
result = reg_model.fit()
print(result.summary())


### Quarterly ###
### Quarterly Lag 24###

analysis = oil_co2_df.copy()
oil_co2_df.columns

analysis_quarter = analysis.query('Month in [12,3,6,9]').groupby('Par_Month').last()[['oil_spot_WTI','Gasoline_Price_US','co2_conc']]

analysis_reg_quarter = np.log(analysis_quarter) - np.log(analysis_quarter.shift(1))
analysis_reg_quarter.dropna(inplace = True)
analysis_reg_quarter['co2_conc'] = analysis_reg_quarter['co2_conc'] - analysis_reg_quarter['co2_conc'].shift(4)
analysis_reg_quarter.dropna(inplace = True)

### Quarterly ###
analysis_reg_quarter_edited = analysis_reg_quarter.copy()

analysis_reg_quarter_edited['chg_oil_spot_WTI_Positive'] = list(map(lambda x : 0 if x <= 0 else x,analysis_reg_quarter['oil_spot_WTI'] ))
analysis_reg_quarter_edited['chg_oil_spot_WTI_Negative'] = list(map(lambda x : 0 if x >= 0 else x,analysis_reg_quarter['oil_spot_WTI'] ))

analysis_reg = analysis_reg_quarter_edited.copy()

analysis_reg['p+_lag1'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Positive'].shift(1)
analysis_reg['p+_lag2'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Positive'].shift(2)
analysis_reg['p+_lag3'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Positive'].shift(3)
analysis_reg['p+_lag4'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Positive'].shift(4)
analysis_reg['p+_lag5'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Positive'].shift(5)
analysis_reg['p+_lag6'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Positive'].shift(6)
analysis_reg['p+_lag7'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Positive'].shift(7)
analysis_reg['p+_lag8'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Positive'].shift(8)
analysis_reg['p+_lag9'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Positive'].shift(9)
analysis_reg['p+_lag10'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Positive'].shift(10)
analysis_reg['p+_lag11'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Positive'].shift(11)
analysis_reg['p+_lag12'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Positive'].shift(12)
analysis_reg['p+_lag13'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Positive'].shift(13)
analysis_reg['p+_lag14'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Positive'].shift(14)
analysis_reg['p+_lag15'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Positive'].shift(15)
analysis_reg['p+_lag16'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Positive'].shift(16)
analysis_reg['p+_lag17'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Positive'].shift(17)
analysis_reg['p+_lag18'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Positive'].shift(18)
analysis_reg['p+_lag19'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Positive'].shift(19)
analysis_reg['p+_lag20'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Positive'].shift(20)
analysis_reg['p+_lag21'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Positive'].shift(21)
analysis_reg['p+_lag22'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Positive'].shift(22)
analysis_reg['p+_lag23'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Positive'].shift(23)
analysis_reg['p+_lag24'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Positive'].shift(24)

analysis_reg['p-_lag1'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Negative'].shift(1)
analysis_reg['p-_lag2'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Negative'].shift(2)
analysis_reg['p-_lag3'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Negative'].shift(3)
analysis_reg['p-_lag4'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Negative'].shift(4)
analysis_reg['p-_lag5'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Negative'].shift(5)
analysis_reg['p-_lag6'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Negative'].shift(6)
analysis_reg['p-_lag7'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Negative'].shift(7)
analysis_reg['p-_lag8'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Negative'].shift(8)
analysis_reg['p-_lag9'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Negative'].shift(9)
analysis_reg['p-_lag10'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Negative'].shift(10)
analysis_reg['p-_lag11'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Negative'].shift(11)
analysis_reg['p-_lag12'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Negative'].shift(12)
analysis_reg['p-_lag13'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Negative'].shift(13)
analysis_reg['p-_lag14'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Negative'].shift(14)
analysis_reg['p-_lag15'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Negative'].shift(15)
analysis_reg['p-_lag16'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Negative'].shift(16)
analysis_reg['p-_lag17'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Negative'].shift(17)
analysis_reg['p-_lag18'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Negative'].shift(18)
analysis_reg['p-_lag19'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Negative'].shift(19)
analysis_reg['p-_lag20'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Negative'].shift(20)
analysis_reg['p-_lag21'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Negative'].shift(21)
analysis_reg['p-_lag22'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Negative'].shift(22)
analysis_reg['p-_lag23'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Negative'].shift(23)
analysis_reg['p-_lag24'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Negative'].shift(24)


analysis_reg = analysis_reg.dropna(subset = ['p+_lag1','p-_lag1','p+_lag2','p-_lag2','p+_lag3','p-_lag3','p+_lag4','p-_lag4','p+_lag5','p-_lag5','p+_lag6','p-_lag6','p+_lag7','p-_lag7','p+_lag8','p-_lag8','p+_lag9','p-_lag9','p+_lag10','p-_lag10','p+_lag11','p-_lag11','p+_lag12','p-_lag12'
                                             ,'p+_lag13','p-_lag13','p+_lag14','p-_lag14','p+_lag15','p-_lag15','p+_lag16','p-_lag16','p+_lag17','p-_lag17','p+_lag18','p-_lag18','p+_lag19','p-_lag19','p+_lag20','p-_lag20','p+_lag21','p-_lag21','p+_lag22','p-_lag22','p+_lag23','p-_lag23','p+_lag24','p-_lag24'])

x = analysis_reg[['chg_oil_spot_WTI_Positive', 'chg_oil_spot_WTI_Negative','p+_lag1','p-_lag1','p+_lag2','p-_lag2','p+_lag3','p-_lag3','p+_lag4','p-_lag4','p+_lag5','p-_lag5','p+_lag6','p-_lag6','p+_lag7','p-_lag7','p+_lag8','p-_lag8','p+_lag9','p-_lag9','p+_lag10','p-_lag10','p+_lag11','p-_lag11','p+_lag12','p-_lag12'
                                             ,'p+_lag13','p-_lag13','p+_lag14','p-_lag14','p+_lag15','p-_lag15','p+_lag16','p-_lag16','p+_lag17','p-_lag17','p+_lag18','p-_lag18','p+_lag19','p-_lag19','p+_lag20','p-_lag20','p+_lag21','p-_lag21','p+_lag22','p-_lag22','p+_lag23','p-_lag23','p+_lag24','p-_lag24']] 

reg_model = sm.OLS(analysis_reg['Gasoline_Price_US'],x)
result = reg_model.fit()
print(result.summary())
                            OLS Regression Results                            
==============================================================================
Dep. Variable:      Gasoline_Price_US   R-squared:                       0.445
Model:                            OLS   Adj. R-squared:                  0.435
Method:                 Least Squares   F-statistic:                     45.29
Date:                Sun, 28 Feb 2021   Prob (F-statistic):           3.60e-15
Time:                        15:24:59   Log-Likelihood:                 100.83
No. Observations:                 115   AIC:                            -197.7
Df Residuals:                     113   BIC:                            -192.2
Df Model:                           2                                         
Covariance Type:            nonrobust                                         
=============================================================================================
                                coef    std err          t      P>|t|      [0.025      0.975]
---------------------------------------------------------------------------------------------
chg_oil_spot_WTI_Positive     0.3110      0.067      4.629      0.000       0.178       0.444
chg_oil_spot_WTI_Negative     0.4111      0.049      8.315      0.000       0.313       0.509
==============================================================================
Omnibus:                       16.327   Durbin-Watson:                   2.754
Prob(Omnibus):                  0.000   Jarque-Bera (JB):               46.673
Skew:                          -0.389   Prob(JB):                     7.33e-11
Kurtosis:                       6.022   Cond. No.                         1.36
==============================================================================

Warnings:
[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.
                            OLS Regression Results                            
==============================================================================
Dep. Variable:      Gasoline_Price_US   R-squared:                       0.490
Model:                            OLS   Adj. R-squared:                  0.450
Method:                 Least Squares   F-statistic:                     12.47
Date:                Sun, 28 Feb 2021   Prob (F-statistic):           2.10e-12
Time:                        15:24:59   Log-Likelihood:                 101.95
No. Observations:                 112   AIC:                            -187.9
Df Residuals:                     104   BIC:                            -166.1
Df Model:                           8                                         
Covariance Type:            nonrobust                                         
=============================================================================================
                                coef    std err          t      P>|t|      [0.025      0.975]
---------------------------------------------------------------------------------------------
chg_oil_spot_WTI_Positive     0.4083      0.103      3.965      0.000       0.204       0.612
chg_oil_spot_WTI_Negative     0.3924      0.053      7.388      0.000       0.287       0.498
p+_lag1                       0.0391      0.103      0.379      0.705      -0.165       0.243
p-_lag1                       0.1472      0.070      2.090      0.039       0.008       0.287
p+_lag2                      -0.0567      0.105     -0.540      0.590      -0.265       0.151
p-_lag2                      -0.0699      0.071     -0.989      0.325      -0.210       0.070
p+_lag3                       0.0302      0.103      0.294      0.770      -0.174       0.234
p-_lag3                      -0.0116      0.072     -0.161      0.872      -0.154       0.131
==============================================================================
Omnibus:                        9.636   Durbin-Watson:                   2.826
Prob(Omnibus):                  0.008   Jarque-Bera (JB):               18.393
Skew:                          -0.263   Prob(JB):                     0.000101
Kurtosis:                       4.915   Cond. No.                         3.69
==============================================================================

Warnings:
[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.
                            OLS Regression Results                            
==============================================================================
Dep. Variable:      Gasoline_Price_US   R-squared:                       0.566
Model:                            OLS   Adj. R-squared:                  0.502
Method:                 Least Squares   F-statistic:                     8.858
Date:                Sun, 28 Feb 2021   Prob (F-statistic):           5.21e-12
Time:                        15:24:59   Log-Likelihood:                 106.69
No. Observations:                 109   AIC:                            -185.4
Df Residuals:                      95   BIC:                            -147.7
Df Model:                          14                                         
Covariance Type:            nonrobust                                         
=============================================================================================
                                coef    std err          t      P>|t|      [0.025      0.975]
---------------------------------------------------------------------------------------------
chg_oil_spot_WTI_Positive     0.3624      0.102      3.541      0.001       0.159       0.566
chg_oil_spot_WTI_Negative     0.4683      0.056      8.316      0.000       0.357       0.580
p+_lag1                       0.0448      0.102      0.439      0.662      -0.158       0.247
p-_lag1                       0.0941      0.071      1.335      0.185      -0.046       0.234
p+_lag2                      -0.0654      0.106     -0.618      0.538      -0.275       0.145
p-_lag2                      -0.0391      0.071     -0.552      0.582      -0.180       0.102
p+_lag3                      -0.0231      0.120     -0.192      0.848      -0.262       0.216
p-_lag3                      -0.0145      0.070     -0.206      0.837      -0.154       0.125
p+_lag4                       0.3416      0.126      2.705      0.008       0.091       0.592
p-_lag4                       0.0525      0.083      0.632      0.529      -0.112       0.217
p+_lag5                      -0.0072      0.117     -0.061      0.951      -0.240       0.226
p-_lag5                      -0.1275      0.085     -1.502      0.137      -0.296       0.041
p+_lag6                      -0.0916      0.115     -0.795      0.429      -0.320       0.137
p-_lag6                       0.1267      0.087      1.463      0.147      -0.045       0.299
==============================================================================
Omnibus:                       15.159   Durbin-Watson:                   2.790
Prob(Omnibus):                  0.001   Jarque-Bera (JB):               22.189
Skew:                          -0.666   Prob(JB):                     1.52e-05
Kurtosis:                       4.765   Cond. No.                         5.11
==============================================================================

Warnings:
[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.
                            OLS Regression Results                            
==============================================================================
Dep. Variable:      Gasoline_Price_US   R-squared:                       0.661
Model:                            OLS   Adj. R-squared:                  0.547
Method:                 Least Squares   F-statistic:                     5.775
Date:                Sun, 28 Feb 2021   Prob (F-statistic):           9.30e-10
Time:                        15:24:59   Log-Likelihood:                 110.97
No. Observations:                 103   AIC:                            -169.9
Df Residuals:                      77   BIC:                            -101.4
Df Model:                          26                                         
Covariance Type:            nonrobust                                         
=============================================================================================
                                coef    std err          t      P>|t|      [0.025      0.975]
---------------------------------------------------------------------------------------------
chg_oil_spot_WTI_Positive     0.4369      0.113      3.857      0.000       0.211       0.663
chg_oil_spot_WTI_Negative     0.4764      0.058      8.182      0.000       0.360       0.592
p+_lag1                      -0.0631      0.114     -0.556      0.580      -0.289       0.163
p-_lag1                       0.1255      0.075      1.668      0.099      -0.024       0.275
p+_lag2                      -0.1393      0.114     -1.222      0.225      -0.366       0.088
p-_lag2                      -0.0714      0.076     -0.939      0.351      -0.223       0.080
p+_lag3                       0.0163      0.130      0.126      0.900      -0.243       0.276
p-_lag3                      -0.0558      0.076     -0.733      0.466      -0.207       0.096
p+_lag4                       0.4699      0.136      3.453      0.001       0.199       0.741
p-_lag4                       0.0271      0.086      0.316      0.753      -0.144       0.198
p+_lag5                      -0.0387      0.132     -0.292      0.771      -0.302       0.225
p-_lag5                      -0.1053      0.090     -1.169      0.246      -0.285       0.074
p+_lag6                      -0.1800      0.144     -1.251      0.215      -0.466       0.106
p-_lag6                       0.1798      0.094      1.912      0.060      -0.007       0.367
p+_lag7                      -0.0306      0.147     -0.208      0.836      -0.324       0.263
p-_lag7                       0.0033      0.092      0.036      0.971      -0.179       0.186
p+_lag8                      -0.0722      0.144     -0.501      0.617      -0.359       0.215
p-_lag8                      -0.0080      0.094     -0.086      0.932      -0.194       0.178
p+_lag9                       0.1335      0.146      0.915      0.363      -0.157       0.424
p-_lag9                      -0.0242      0.098     -0.248      0.805      -0.219       0.170
p+_lag10                      0.0108      0.147      0.074      0.941      -0.282       0.303
p-_lag10                     -0.1317      0.097     -1.353      0.180      -0.325       0.062
p+_lag11                      0.1336      0.129      1.034      0.304      -0.124       0.391
p-_lag11                     -0.1281      0.095     -1.349      0.181      -0.317       0.061
p+_lag12                     -0.0466      0.123     -0.378      0.707      -0.292       0.199
p-_lag12                      0.3099      0.095      3.247      0.002       0.120       0.500
==============================================================================
Omnibus:                       13.189   Durbin-Watson:                   2.848
Prob(Omnibus):                  0.001   Jarque-Bera (JB):               22.377
Skew:                          -0.527   Prob(JB):                     1.38e-05
Kurtosis:                       5.026   Cond. No.                         9.14
==============================================================================

Warnings:
[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.
                            OLS Regression Results                            
==============================================================================
Dep. Variable:      Gasoline_Price_US   R-squared:                       0.820
Model:                            OLS   Adj. R-squared:                  0.601
Method:                 Least Squares   F-statistic:                     3.745
Date:                Sun, 28 Feb 2021   Prob (F-statistic):           1.52e-05
Time:                        15:24:59   Log-Likelihood:                 122.30
No. Observations:                  91   AIC:                            -144.6
Df Residuals:                      41   BIC:                            -19.06
Df Model:                          50                                         
Covariance Type:            nonrobust                                         
=============================================================================================
                                coef    std err          t      P>|t|      [0.025      0.975]
---------------------------------------------------------------------------------------------
chg_oil_spot_WTI_Positive     0.4483      0.130      3.446      0.001       0.186       0.711
chg_oil_spot_WTI_Negative     0.4659      0.074      6.337      0.000       0.317       0.614
p+_lag1                      -0.1240      0.130     -0.952      0.347      -0.387       0.139
p-_lag1                       0.1652      0.087      1.898      0.065      -0.011       0.341
p+_lag2                      -0.0697      0.135     -0.518      0.608      -0.342       0.202
p-_lag2                      -0.1852      0.089     -2.092      0.043      -0.364      -0.006
p+_lag3                      -0.0215      0.172     -0.125      0.901      -0.370       0.327
p-_lag3                       0.0078      0.091      0.085      0.932      -0.176       0.192
p+_lag4                       0.3051      0.182      1.676      0.101      -0.063       0.673
p-_lag4                       0.0794      0.103      0.768      0.447      -0.129       0.288
p+_lag5                      -0.0446      0.192     -0.233      0.817      -0.432       0.342
p-_lag5                      -0.1004      0.111     -0.903      0.372      -0.325       0.124
p+_lag6                      -0.1931      0.192     -1.003      0.322      -0.582       0.196
p-_lag6                       0.1184      0.112      1.061      0.295      -0.107       0.344
p+_lag7                       0.0924      0.197      0.470      0.641      -0.305       0.490
p-_lag7                      -0.0796      0.112     -0.713      0.480      -0.305       0.146
p+_lag8                       0.1052      0.192      0.548      0.587      -0.283       0.493
p-_lag8                      -0.0078      0.115     -0.067      0.947      -0.240       0.224
p+_lag9                       0.0304      0.196      0.155      0.877      -0.366       0.427
p-_lag9                       0.0600      0.118      0.510      0.613      -0.178       0.297
p+_lag10                     -0.0338      0.210     -0.161      0.873      -0.458       0.390
p-_lag10                     -0.1049      0.116     -0.904      0.371      -0.339       0.129
p+_lag11                     -0.0623      0.215     -0.290      0.773      -0.496       0.372
p-_lag11                     -0.0635      0.117     -0.543      0.590      -0.299       0.173
p+_lag12                     -0.2605      0.223     -1.171      0.248      -0.710       0.189
p-_lag12                      0.3346      0.119      2.803      0.008       0.094       0.576
p+_lag13                      0.2887      0.226      1.277      0.209      -0.168       0.746
p-_lag13                     -0.2949      0.123     -2.399      0.021      -0.543      -0.047
p+_lag14                      0.2154      0.215      1.000      0.323      -0.220       0.650
p-_lag14                      0.0612      0.120      0.509      0.613      -0.181       0.304
p+_lag15                     -0.0635      0.217     -0.292      0.772      -0.503       0.375
p-_lag15                     -0.1311      0.120     -1.095      0.280      -0.373       0.111
p+_lag16                      0.0193      0.208      0.093      0.926      -0.401       0.439
p-_lag16                      0.2763      0.120      2.299      0.027       0.034       0.519
p+_lag17                     -0.3204      0.191     -1.682      0.100      -0.705       0.064
p-_lag17                     -0.0152      0.119     -0.128      0.899      -0.256       0.225
p+_lag18                      0.1441      0.189      0.761      0.451      -0.238       0.527
p-_lag18                     -0.1166      0.120     -0.969      0.338      -0.360       0.126
p+_lag19                      0.0032      0.184      0.017      0.986      -0.369       0.375
p-_lag19                      0.0105      0.116      0.090      0.928      -0.224       0.245
p+_lag20                     -0.1402      0.181     -0.774      0.443      -0.506       0.226
p-_lag20                      0.1076      0.125      0.858      0.396      -0.146       0.361
p+_lag21                      0.1938      0.184      1.051      0.299      -0.178       0.566
p-_lag21                     -0.2031      0.126     -1.616      0.114      -0.457       0.051
p+_lag22                     -0.0835      0.189     -0.442      0.661      -0.465       0.298
p-_lag22                      0.1101      0.134      0.822      0.416      -0.160       0.380
p+_lag23                     -0.0698      0.162     -0.432      0.668      -0.397       0.257
p-_lag23                      0.0869      0.128      0.679      0.501      -0.172       0.346
p+_lag24                      0.2404      0.148      1.630      0.111      -0.057       0.538
p-_lag24                     -0.0314      0.140     -0.224      0.824      -0.315       0.252
==============================================================================
Omnibus:                        1.890   Durbin-Watson:                   2.599
Prob(Omnibus):                  0.389   Jarque-Bera (JB):                1.376
Skew:                          -0.074   Prob(JB):                        0.503
Kurtosis:                       3.584   Cond. No.                         21.2
==============================================================================

Warnings:
[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.
In [188]:
### Quarterly CO2 ###
### Quarterly Lag 0###

analysis = oil_co2_df.copy()
oil_co2_df.columns

analysis_quarter = analysis.query('Month in [12,3,6,9]').groupby('Par_Month').last()[['oil_spot_WTI','Gasoline_Price_US','co2_conc']]

analysis_reg_quarter = np.log(analysis_quarter) - np.log(analysis_quarter.shift(1))
analysis_reg_quarter.dropna(inplace = True)
analysis_reg_quarter['co2_conc'] = analysis_reg_quarter['co2_conc'] - analysis_reg_quarter['co2_conc'].shift(4)
analysis_reg_quarter.dropna(inplace = True)

### Quarterly ###
analysis_reg_quarter_edited = analysis_reg_quarter.copy()

analysis_reg_quarter_edited['chg_oil_spot_WTI_Positive'] = list(map(lambda x : 0 if x <= 0 else x,analysis_reg_quarter['oil_spot_WTI'] ))
analysis_reg_quarter_edited['chg_oil_spot_WTI_Negative'] = list(map(lambda x : 0 if x >= 0 else x,analysis_reg_quarter['oil_spot_WTI'] ))

analysis_reg = analysis_reg_quarter_edited.copy()

x = analysis_reg[['chg_oil_spot_WTI_Positive', 'chg_oil_spot_WTI_Negative']] 

reg_model = sm.OLS(analysis_reg['co2_conc'],x)
result = reg_model.fit()
print(result.summary())

### Quarterly ###
### Quarterly Lag 3###

analysis = oil_co2_df.copy()
oil_co2_df.columns

analysis_quarter = analysis.query('Month in [12,3,6,9]').groupby('Par_Month').last()[['oil_spot_WTI','Gasoline_Price_US','co2_conc']]

analysis_reg_quarter = np.log(analysis_quarter) - np.log(analysis_quarter.shift(1))
analysis_reg_quarter.dropna(inplace = True)
analysis_reg_quarter['co2_conc'] = analysis_reg_quarter['co2_conc'] - analysis_reg_quarter['co2_conc'].shift(4)
analysis_reg_quarter.dropna(inplace = True)

### Quarterly ###
analysis_reg_quarter_edited = analysis_reg_quarter.copy()

analysis_reg_quarter_edited['chg_oil_spot_WTI_Positive'] = list(map(lambda x : 0 if x <= 0 else x,analysis_reg_quarter['oil_spot_WTI'] ))
analysis_reg_quarter_edited['chg_oil_spot_WTI_Negative'] = list(map(lambda x : 0 if x >= 0 else x,analysis_reg_quarter['oil_spot_WTI'] ))

analysis_reg = analysis_reg_quarter_edited.copy()


analysis_reg['p+_lag1'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Positive'].shift(1)
analysis_reg['p+_lag2'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Positive'].shift(2)
analysis_reg['p+_lag3'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Positive'].shift(3)


analysis_reg['p-_lag1'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Negative'].shift(1)
analysis_reg['p-_lag2'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Negative'].shift(2)
analysis_reg['p-_lag3'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Negative'].shift(3)


analysis_reg = analysis_reg.dropna(subset = ['p+_lag1','p-_lag1','p+_lag2','p-_lag2','p+_lag3','p-_lag3'])

x = analysis_reg[['chg_oil_spot_WTI_Positive', 'chg_oil_spot_WTI_Negative','p+_lag1','p-_lag1','p+_lag2','p-_lag2','p+_lag3','p-_lag3']] 

reg_model = sm.OLS(analysis_reg['co2_conc'],x)
result = reg_model.fit()
print(result.summary())


### Quarterly ###
### Quarterly Lag 6###

analysis = oil_co2_df.copy()
oil_co2_df.columns

analysis = oil_co2_df.copy()
oil_co2_df.columns

analysis_quarter = analysis.query('Month in [12,3,6,9]').groupby('Par_Month').last()[['oil_spot_WTI','Gasoline_Price_US','co2_conc']]

analysis_reg_quarter = np.log(analysis_quarter) - np.log(analysis_quarter.shift(1))
analysis_reg_quarter.dropna(inplace = True)
analysis_reg_quarter['co2_conc'] = analysis_reg_quarter['co2_conc'] - analysis_reg_quarter['co2_conc'].shift(4)
analysis_reg_quarter.dropna(inplace = True)

### Quarterly ###
analysis_reg_quarter_edited = analysis_reg_quarter.copy()

analysis_reg_quarter_edited['chg_oil_spot_WTI_Positive'] = list(map(lambda x : 0 if x <= 0 else x,analysis_reg_quarter['oil_spot_WTI'] ))
analysis_reg_quarter_edited['chg_oil_spot_WTI_Negative'] = list(map(lambda x : 0 if x >= 0 else x,analysis_reg_quarter['oil_spot_WTI'] ))

analysis_reg = analysis_reg_quarter_edited.copy()

analysis_reg['p+_lag1'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Positive'].shift(1)
analysis_reg['p+_lag2'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Positive'].shift(2)
analysis_reg['p+_lag3'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Positive'].shift(3)
analysis_reg['p+_lag4'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Positive'].shift(4)
analysis_reg['p+_lag5'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Positive'].shift(5)
analysis_reg['p+_lag6'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Positive'].shift(6)

analysis_reg['p-_lag1'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Negative'].shift(1)
analysis_reg['p-_lag2'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Negative'].shift(2)
analysis_reg['p-_lag3'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Negative'].shift(3)
analysis_reg['p-_lag4'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Negative'].shift(4)
analysis_reg['p-_lag5'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Negative'].shift(5)
analysis_reg['p-_lag6'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Negative'].shift(6)


analysis_reg = analysis_reg.dropna(subset = ['p+_lag1','p-_lag1','p+_lag2','p-_lag2','p+_lag3','p-_lag3','p+_lag4','p-_lag4','p+_lag5','p-_lag5','p+_lag6','p-_lag6'])

x = analysis_reg[['chg_oil_spot_WTI_Positive', 'chg_oil_spot_WTI_Negative','p+_lag1','p-_lag1','p+_lag2','p-_lag2','p+_lag3','p-_lag3','p+_lag4','p-_lag4','p+_lag5','p-_lag5','p+_lag6','p-_lag6']] 

reg_model = sm.OLS(analysis_reg['co2_conc'],x)
result = reg_model.fit()
print(result.summary())


### quarterly ###
### Quarterly Lag 12###

analysis = oil_co2_df.copy()
oil_co2_df.columns

analysis_quarter = analysis.query('Month in [12,3,6,9]').groupby('Par_Month').last()[['oil_spot_WTI','Gasoline_Price_US','co2_conc']]

analysis_reg_quarter = np.log(analysis_quarter) - np.log(analysis_quarter.shift(1))
analysis_reg_quarter.dropna(inplace = True)
analysis_reg_quarter['co2_conc'] = analysis_reg_quarter['co2_conc'] - analysis_reg_quarter['co2_conc'].shift(4)
analysis_reg_quarter.dropna(inplace = True)

### Quarterly ###
analysis_reg_quarter_edited = analysis_reg_quarter.copy()

analysis_reg_quarter_edited['chg_oil_spot_WTI_Positive'] = list(map(lambda x : 0 if x <= 0 else x,analysis_reg_quarter['oil_spot_WTI'] ))
analysis_reg_quarter_edited['chg_oil_spot_WTI_Negative'] = list(map(lambda x : 0 if x >= 0 else x,analysis_reg_quarter['oil_spot_WTI'] ))

analysis_reg = analysis_reg_quarter_edited.copy()

analysis_reg['p+_lag1'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Positive'].shift(1)
analysis_reg['p+_lag2'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Positive'].shift(2)
analysis_reg['p+_lag3'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Positive'].shift(3)
analysis_reg['p+_lag4'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Positive'].shift(4)
analysis_reg['p+_lag5'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Positive'].shift(5)
analysis_reg['p+_lag6'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Positive'].shift(6)
analysis_reg['p+_lag7'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Positive'].shift(7)
analysis_reg['p+_lag8'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Positive'].shift(8)
analysis_reg['p+_lag9'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Positive'].shift(9)
analysis_reg['p+_lag10'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Positive'].shift(10)
analysis_reg['p+_lag11'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Positive'].shift(11)
analysis_reg['p+_lag12'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Positive'].shift(12)

analysis_reg['p-_lag1'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Negative'].shift(1)
analysis_reg['p-_lag2'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Negative'].shift(2)
analysis_reg['p-_lag3'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Negative'].shift(3)
analysis_reg['p-_lag4'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Negative'].shift(4)
analysis_reg['p-_lag5'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Negative'].shift(5)
analysis_reg['p-_lag6'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Negative'].shift(6)
analysis_reg['p-_lag7'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Negative'].shift(7)
analysis_reg['p-_lag8'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Negative'].shift(8)
analysis_reg['p-_lag9'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Negative'].shift(9)
analysis_reg['p-_lag10'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Negative'].shift(10)
analysis_reg['p-_lag11'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Negative'].shift(11)
analysis_reg['p-_lag12'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Negative'].shift(12)


analysis_reg = analysis_reg.dropna(subset = ['p+_lag1','p-_lag1','p+_lag2','p-_lag2','p+_lag3','p-_lag3','p+_lag4','p-_lag4','p+_lag5','p-_lag5','p+_lag6','p-_lag6','p+_lag7','p-_lag7','p+_lag8','p-_lag8','p+_lag9','p-_lag9','p+_lag10','p-_lag10','p+_lag11','p-_lag11','p+_lag12','p-_lag12'])

x = analysis_reg[['chg_oil_spot_WTI_Positive', 'chg_oil_spot_WTI_Negative','p+_lag1','p-_lag1','p+_lag2','p-_lag2','p+_lag3','p-_lag3','p+_lag4','p-_lag4','p+_lag5','p-_lag5','p+_lag6','p-_lag6','p+_lag7','p-_lag7','p+_lag8','p-_lag8','p+_lag9','p-_lag9','p+_lag10','p-_lag10','p+_lag11','p-_lag11','p+_lag12','p-_lag12']] 

reg_model = sm.OLS(analysis_reg['co2_conc'],x)
result = reg_model.fit()
print(result.summary())


### Quarterly ###
### Quarterly Lag 24###

analysis = oil_co2_df.copy()
oil_co2_df.columns

analysis_quarter = analysis.query('Month in [12,3,6,9]').groupby('Par_Month').last()[['oil_spot_WTI','Gasoline_Price_US','co2_conc']]

analysis_reg_quarter = np.log(analysis_quarter) - np.log(analysis_quarter.shift(1))
analysis_reg_quarter.dropna(inplace = True)
analysis_reg_quarter['co2_conc'] = analysis_reg_quarter['co2_conc'] - analysis_reg_quarter['co2_conc'].shift(4)
analysis_reg_quarter.dropna(inplace = True)

### Quarterly ###
analysis_reg_quarter_edited = analysis_reg_quarter.copy()

analysis_reg_quarter_edited['chg_oil_spot_WTI_Positive'] = list(map(lambda x : 0 if x <= 0 else x,analysis_reg_quarter['oil_spot_WTI'] ))
analysis_reg_quarter_edited['chg_oil_spot_WTI_Negative'] = list(map(lambda x : 0 if x >= 0 else x,analysis_reg_quarter['oil_spot_WTI'] ))

analysis_reg = analysis_reg_quarter_edited.copy()

analysis_reg['p+_lag1'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Positive'].shift(1)
analysis_reg['p+_lag2'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Positive'].shift(2)
analysis_reg['p+_lag3'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Positive'].shift(3)
analysis_reg['p+_lag4'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Positive'].shift(4)
analysis_reg['p+_lag5'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Positive'].shift(5)
analysis_reg['p+_lag6'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Positive'].shift(6)
analysis_reg['p+_lag7'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Positive'].shift(7)
analysis_reg['p+_lag8'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Positive'].shift(8)
analysis_reg['p+_lag9'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Positive'].shift(9)
analysis_reg['p+_lag10'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Positive'].shift(10)
analysis_reg['p+_lag11'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Positive'].shift(11)
analysis_reg['p+_lag12'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Positive'].shift(12)
analysis_reg['p+_lag13'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Positive'].shift(13)
analysis_reg['p+_lag14'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Positive'].shift(14)
analysis_reg['p+_lag15'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Positive'].shift(15)
analysis_reg['p+_lag16'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Positive'].shift(16)
analysis_reg['p+_lag17'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Positive'].shift(17)
analysis_reg['p+_lag18'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Positive'].shift(18)
analysis_reg['p+_lag19'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Positive'].shift(19)
analysis_reg['p+_lag20'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Positive'].shift(20)
analysis_reg['p+_lag21'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Positive'].shift(21)
analysis_reg['p+_lag22'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Positive'].shift(22)
analysis_reg['p+_lag23'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Positive'].shift(23)
analysis_reg['p+_lag24'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Positive'].shift(24)

analysis_reg['p-_lag1'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Negative'].shift(1)
analysis_reg['p-_lag2'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Negative'].shift(2)
analysis_reg['p-_lag3'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Negative'].shift(3)
analysis_reg['p-_lag4'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Negative'].shift(4)
analysis_reg['p-_lag5'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Negative'].shift(5)
analysis_reg['p-_lag6'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Negative'].shift(6)
analysis_reg['p-_lag7'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Negative'].shift(7)
analysis_reg['p-_lag8'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Negative'].shift(8)
analysis_reg['p-_lag9'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Negative'].shift(9)
analysis_reg['p-_lag10'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Negative'].shift(10)
analysis_reg['p-_lag11'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Negative'].shift(11)
analysis_reg['p-_lag12'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Negative'].shift(12)
analysis_reg['p-_lag13'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Negative'].shift(13)
analysis_reg['p-_lag14'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Negative'].shift(14)
analysis_reg['p-_lag15'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Negative'].shift(15)
analysis_reg['p-_lag16'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Negative'].shift(16)
analysis_reg['p-_lag17'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Negative'].shift(17)
analysis_reg['p-_lag18'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Negative'].shift(18)
analysis_reg['p-_lag19'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Negative'].shift(19)
analysis_reg['p-_lag20'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Negative'].shift(20)
analysis_reg['p-_lag21'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Negative'].shift(21)
analysis_reg['p-_lag22'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Negative'].shift(22)
analysis_reg['p-_lag23'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Negative'].shift(23)
analysis_reg['p-_lag24'] = analysis_reg_quarter_edited['chg_oil_spot_WTI_Negative'].shift(24)


analysis_reg = analysis_reg.dropna(subset = ['p+_lag1','p-_lag1','p+_lag2','p-_lag2','p+_lag3','p-_lag3','p+_lag4','p-_lag4','p+_lag5','p-_lag5','p+_lag6','p-_lag6','p+_lag7','p-_lag7','p+_lag8','p-_lag8','p+_lag9','p-_lag9','p+_lag10','p-_lag10','p+_lag11','p-_lag11','p+_lag12','p-_lag12'
                                             ,'p+_lag13','p-_lag13','p+_lag14','p-_lag14','p+_lag15','p-_lag15','p+_lag16','p-_lag16','p+_lag17','p-_lag17','p+_lag18','p-_lag18','p+_lag19','p-_lag19','p+_lag20','p-_lag20','p+_lag21','p-_lag21','p+_lag22','p-_lag22','p+_lag23','p-_lag23','p+_lag24','p-_lag24'])

x = analysis_reg[['chg_oil_spot_WTI_Positive', 'chg_oil_spot_WTI_Negative','p+_lag1','p-_lag1','p+_lag2','p-_lag2','p+_lag3','p-_lag3','p+_lag4','p-_lag4','p+_lag5','p-_lag5','p+_lag6','p-_lag6','p+_lag7','p-_lag7','p+_lag8','p-_lag8','p+_lag9','p-_lag9','p+_lag10','p-_lag10','p+_lag11','p-_lag11','p+_lag12','p-_lag12'
                                             ,'p+_lag13','p-_lag13','p+_lag14','p-_lag14','p+_lag15','p-_lag15','p+_lag16','p-_lag16','p+_lag17','p-_lag17','p+_lag18','p-_lag18','p+_lag19','p-_lag19','p+_lag20','p-_lag20','p+_lag21','p-_lag21','p+_lag22','p-_lag22','p+_lag23','p-_lag23','p+_lag24','p-_lag24']] 

reg_model = sm.OLS(analysis_reg['co2_conc'],x)
result = reg_model.fit()
print(result.summary())
                            OLS Regression Results                            
==============================================================================
Dep. Variable:               co2_conc   R-squared:                       0.011
Model:                            OLS   Adj. R-squared:                 -0.007
Method:                 Least Squares   F-statistic:                    0.6017
Date:                Sun, 28 Feb 2021   Prob (F-statistic):              0.550
Time:                        15:24:59   Log-Likelihood:                 540.92
No. Observations:                 115   AIC:                            -1078.
Df Residuals:                     113   BIC:                            -1072.
Df Model:                           2                                         
Covariance Type:            nonrobust                                         
=============================================================================================
                                coef    std err          t      P>|t|      [0.025      0.975]
---------------------------------------------------------------------------------------------
chg_oil_spot_WTI_Positive    -0.0016      0.001     -1.096      0.275      -0.005       0.001
chg_oil_spot_WTI_Negative   4.43e-05      0.001      0.041      0.967      -0.002       0.002
==============================================================================
Omnibus:                        0.039   Durbin-Watson:                   2.807
Prob(Omnibus):                  0.981   Jarque-Bera (JB):                0.066
Skew:                           0.038   Prob(JB):                        0.968
Kurtosis:                       2.911   Cond. No.                         1.36
==============================================================================

Warnings:
[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.
                            OLS Regression Results                            
==============================================================================
Dep. Variable:               co2_conc   R-squared:                       0.189
Model:                            OLS   Adj. R-squared:                  0.127
Method:                 Least Squares   F-statistic:                     3.031
Date:                Sun, 28 Feb 2021   Prob (F-statistic):            0.00421
Time:                        15:25:00   Log-Likelihood:                 540.10
No. Observations:                 112   AIC:                            -1064.
Df Residuals:                     104   BIC:                            -1042.
Df Model:                           8                                         
Covariance Type:            nonrobust                                         
=============================================================================================
                                coef    std err          t      P>|t|      [0.025      0.975]
---------------------------------------------------------------------------------------------
chg_oil_spot_WTI_Positive    -0.0020      0.002     -0.951      0.344      -0.006       0.002
chg_oil_spot_WTI_Negative    -0.0003      0.001     -0.247      0.805      -0.002       0.002
p+_lag1                      -0.0016      0.002     -0.774      0.440      -0.006       0.002
p-_lag1                       0.0019      0.001      1.370      0.174      -0.001       0.005
p+_lag2                      -0.0016      0.002     -0.765      0.446      -0.006       0.003
p-_lag2                      -0.0040      0.001     -2.815      0.006      -0.007      -0.001
p+_lag3                       0.0045      0.002      2.183      0.031       0.000       0.009
p-_lag3                       0.0009      0.001      0.599      0.551      -0.002       0.004
==============================================================================
Omnibus:                        0.670   Durbin-Watson:                   2.863
Prob(Omnibus):                  0.715   Jarque-Bera (JB):                0.793
Skew:                          -0.162   Prob(JB):                        0.673
Kurtosis:                       2.744   Cond. No.                         3.69
==============================================================================

Warnings:
[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.
                            OLS Regression Results                            
==============================================================================
Dep. Variable:               co2_conc   R-squared:                       0.225
Model:                            OLS   Adj. R-squared:                  0.110
Method:                 Least Squares   F-statistic:                     1.965
Date:                Sun, 28 Feb 2021   Prob (F-statistic):             0.0288
Time:                        15:25:00   Log-Likelihood:                 530.14
No. Observations:                 109   AIC:                            -1032.
Df Residuals:                      95   BIC:                            -994.6
Df Model:                          14                                         
Covariance Type:            nonrobust                                         
=============================================================================================
                                coef    std err          t      P>|t|      [0.025      0.975]
---------------------------------------------------------------------------------------------
chg_oil_spot_WTI_Positive    -0.0021      0.002     -1.015      0.313      -0.006       0.002
chg_oil_spot_WTI_Negative  5.508e-05      0.001      0.048      0.962      -0.002       0.002
p+_lag1                      -0.0018      0.002     -0.852      0.396      -0.006       0.002
p-_lag1                       0.0019      0.001      1.335      0.185      -0.001       0.005
p+_lag2                      -0.0023      0.002     -1.047      0.298      -0.007       0.002
p-_lag2                      -0.0041      0.001     -2.791      0.006      -0.007      -0.001
p+_lag3                       0.0029      0.002      1.180      0.241      -0.002       0.008
p-_lag3                       0.0010      0.001      0.711      0.479      -0.002       0.004
p+_lag4                       0.0018      0.003      0.698      0.487      -0.003       0.007
p-_lag4                      -0.0022      0.002     -1.297      0.198      -0.006       0.001
p+_lag5                       0.0003      0.002      0.127      0.899      -0.004       0.005
p-_lag5                      -0.0004      0.002     -0.204      0.839      -0.004       0.003
p+_lag6                      -0.0007      0.002     -0.302      0.763      -0.005       0.004
p-_lag6                     4.34e-05      0.002      0.024      0.981      -0.003       0.004
==============================================================================
Omnibus:                        0.644   Durbin-Watson:                   2.766
Prob(Omnibus):                  0.725   Jarque-Bera (JB):                0.604
Skew:                          -0.177   Prob(JB):                        0.739
Kurtosis:                       2.915   Cond. No.                         5.11
==============================================================================

Warnings:
[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.
                            OLS Regression Results                            
==============================================================================
Dep. Variable:               co2_conc   R-squared:                       0.291
Model:                            OLS   Adj. R-squared:                  0.051
Method:                 Least Squares   F-statistic:                     1.214
Date:                Sun, 28 Feb 2021   Prob (F-statistic):              0.253
Time:                        15:25:00   Log-Likelihood:                 504.52
No. Observations:                 103   AIC:                            -957.0
Df Residuals:                      77   BIC:                            -888.5
Df Model:                          26                                         
Covariance Type:            nonrobust                                         
=============================================================================================
                                coef    std err          t      P>|t|      [0.025      0.975]
---------------------------------------------------------------------------------------------
chg_oil_spot_WTI_Positive    -0.0009      0.002     -0.370      0.712      -0.006       0.004
chg_oil_spot_WTI_Negative    -0.0002      0.001     -0.131      0.896      -0.003       0.002
p+_lag1                      -0.0026      0.002     -1.060      0.293      -0.008       0.002
p-_lag1                       0.0032      0.002      1.936      0.057   -9.18e-05       0.006
p+_lag2                      -0.0026      0.002     -1.024      0.309      -0.008       0.002
p-_lag2                      -0.0045      0.002     -2.711      0.008      -0.008      -0.001
p+_lag3                       0.0040      0.003      1.389      0.169      -0.002       0.010
p-_lag3                       0.0004      0.002      0.228      0.820      -0.003       0.004
p+_lag4                       0.0022      0.003      0.726      0.470      -0.004       0.008
p-_lag4                      -0.0017      0.002     -0.923      0.359      -0.005       0.002
p+_lag5                       0.0020      0.003      0.702      0.485      -0.004       0.008
p-_lag5                      -0.0010      0.002     -0.498      0.620      -0.005       0.003
p+_lag6                       0.0014      0.003      0.429      0.669      -0.005       0.008
p-_lag6                       0.0006      0.002      0.301      0.764      -0.003       0.005
p+_lag7                      -0.0040      0.003     -1.239      0.219      -0.010       0.002
p-_lag7                       0.0018      0.002      0.912      0.364      -0.002       0.006
p+_lag8                       0.0012      0.003      0.376      0.708      -0.005       0.007
p-_lag8                       0.0014      0.002      0.689      0.493      -0.003       0.005
p+_lag9                      -0.0012      0.003     -0.389      0.699      -0.008       0.005
p-_lag9                      -0.0005      0.002     -0.223      0.824      -0.005       0.004
p+_lag10                      0.0019      0.003      0.584      0.561      -0.005       0.008
p-_lag10                     -0.0005      0.002     -0.224      0.823      -0.005       0.004
p+_lag11                      0.0006      0.003      0.225      0.822      -0.005       0.006
p-_lag11                     7.1e-05      0.002      0.034      0.973      -0.004       0.004
p+_lag12                     -0.0007      0.003     -0.252      0.802      -0.006       0.005
p-_lag12                      0.0012      0.002      0.592      0.556      -0.003       0.005
==============================================================================
Omnibus:                        1.586   Durbin-Watson:                   2.729
Prob(Omnibus):                  0.452   Jarque-Bera (JB):                1.369
Skew:                          -0.282   Prob(JB):                        0.504
Kurtosis:                       2.991   Cond. No.                         9.14
==============================================================================

Warnings:
[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.
                            OLS Regression Results                            
==============================================================================
Dep. Variable:               co2_conc   R-squared:                       0.533
Model:                            OLS   Adj. R-squared:                 -0.037
Method:                 Least Squares   F-statistic:                    0.9359
Date:                Sun, 28 Feb 2021   Prob (F-statistic):              0.591
Time:                        15:25:00   Log-Likelihood:                 464.11
No. Observations:                  91   AIC:                            -828.2
Df Residuals:                      41   BIC:                            -702.7
Df Model:                          50                                         
Covariance Type:            nonrobust                                         
=============================================================================================
                                coef    std err          t      P>|t|      [0.025      0.975]
---------------------------------------------------------------------------------------------
chg_oil_spot_WTI_Positive    -0.0008      0.003     -0.250      0.804      -0.007       0.005
chg_oil_spot_WTI_Negative     0.0015      0.002      0.894      0.376      -0.002       0.005
p+_lag1                       0.0003      0.003      0.085      0.932      -0.006       0.006
p-_lag1                       0.0035      0.002      1.727      0.092      -0.001       0.008
p+_lag2                      -0.0050      0.003     -1.580      0.122      -0.011       0.001
p-_lag2                      -0.0039      0.002     -1.873      0.068      -0.008       0.000
p+_lag3                       0.0049      0.004      1.218      0.230      -0.003       0.013
p-_lag3                       0.0010      0.002      0.466      0.644      -0.003       0.005
p+_lag4                       0.0036      0.004      0.856      0.397      -0.005       0.012
p-_lag4                      -0.0026      0.002     -1.088      0.283      -0.008       0.002
p+_lag5                       0.0050      0.004      1.123      0.268      -0.004       0.014
p-_lag5                      -0.0007      0.003     -0.282      0.779      -0.006       0.005
p+_lag6                   -4.497e-05      0.004     -0.010      0.992      -0.009       0.009
p-_lag6                     -2.2e-05      0.003     -0.008      0.993      -0.005       0.005
p+_lag7                      -0.0072      0.005     -1.561      0.126      -0.016       0.002
p-_lag7                       0.0032      0.003      1.212      0.232      -0.002       0.008
p+_lag8                   -8.313e-05      0.004     -0.019      0.985      -0.009       0.009
p-_lag8                       0.0019      0.003      0.717      0.478      -0.003       0.007
p+_lag9                      -0.0008      0.005     -0.171      0.865      -0.010       0.008
p-_lag9                      -0.0018      0.003     -0.642      0.525      -0.007       0.004
p+_lag10                      0.0077      0.005      1.565      0.125      -0.002       0.018
p-_lag10                     -0.0016      0.003     -0.588      0.560      -0.007       0.004
p+_lag11                     -0.0001      0.005     -0.029      0.977      -0.010       0.010
p-_lag11                      0.0009      0.003      0.323      0.748      -0.005       0.006
p+_lag12                     -0.0010      0.005     -0.189      0.851      -0.011       0.010
p-_lag12                      0.0006      0.003      0.223      0.825      -0.005       0.006
p+_lag13                      0.0008      0.005      0.153      0.879      -0.010       0.011
p-_lag13                      0.0027      0.003      0.937      0.354      -0.003       0.008
p+_lag14                     -0.0028      0.005     -0.556      0.581      -0.013       0.007
p-_lag14                     -0.0004      0.003     -0.132      0.896      -0.006       0.005
p+_lag15                     -0.0018      0.005     -0.363      0.719      -0.012       0.008
p-_lag15                     -0.0006      0.003     -0.227      0.822      -0.006       0.005
p+_lag16                      0.0004      0.005      0.080      0.937      -0.009       0.010
p-_lag16                     -0.0013      0.003     -0.456      0.651      -0.007       0.004
p+_lag17                     -0.0011      0.004     -0.253      0.801      -0.010       0.008
p-_lag17                     -0.0014      0.003     -0.515      0.609      -0.007       0.004
p+_lag18                      0.0004      0.004      0.081      0.936      -0.009       0.009
p-_lag18                      0.0001      0.003      0.036      0.972      -0.006       0.006
p+_lag19                      0.0018      0.004      0.412      0.683      -0.007       0.010
p-_lag19                     -0.0027      0.003     -0.995      0.326      -0.008       0.003
p+_lag20                     -0.0011      0.004     -0.262      0.795      -0.010       0.007
p-_lag20                      0.0025      0.003      0.864      0.392      -0.003       0.008
p+_lag21                     -0.0015      0.004     -0.349      0.729      -0.010       0.007
p-_lag21                     -0.0032      0.003     -1.084      0.285      -0.009       0.003
p+_lag22                     -0.0027      0.004     -0.604      0.549      -0.012       0.006
p-_lag22                      0.0037      0.003      1.168      0.249      -0.003       0.010
p+_lag23                     -0.0085      0.004     -2.260      0.029      -0.016      -0.001
p-_lag23                      0.0012      0.003      0.413      0.682      -0.005       0.007
p+_lag24                      0.0068      0.003      1.967      0.056      -0.000       0.014
p-_lag24                     -0.0075      0.003     -2.277      0.028      -0.014      -0.001
==============================================================================
Omnibus:                        0.765   Durbin-Watson:                   2.583
Prob(Omnibus):                  0.682   Jarque-Bera (JB):                0.667
Skew:                          -0.207   Prob(JB):                        0.716
Kurtosis:                       2.931   Cond. No.                         21.2
==============================================================================

Warnings:
[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.

7. Granger and check correlation

In [189]:
main_frame_granger = oil_co2_df.copy()
oil_price_month = main_frame_granger['Month'].to_list()
quarter = []
for i in range(len(oil_price_month)):
    if oil_price_month[i] in [1,2,3]:
        #print(oil_price_month[i])
        quarter.append(1)
    elif oil_price_month[i] in [4,5,6]:
        quarter.append(2)
    elif oil_price_month[i] in [7,8,9]:
        quarter.append(3)
    elif oil_price_month[i] in [10,11,12]:
        quarter.append(4)
    else:
        quarter.append(oil_price_month[i])
        
main_frame_granger['Quarter'] = quarter
main_frame_granger = main_frame_granger.drop(columns = 'month')
In [190]:
main_frame_granger
Out[190]:
Weekindex Date Year Month Week Day Par_Month Par_Day oil_spot_WTI oil_spot_Brent ... day decimal average ndays 1_year_ago 10_years_ago increase_since_1800 co2_conc chg_co2_conc Quarter
Par_Week
19910205 266 2/1/1991 1991 2 5 1 199102 19910901 21.33 20.80 ... 3.0 1991.0918 355.23 7.0 354.95 340.03 74.73 355.23 NaN 1
19910206 267 2/8/1991 1991 2 6 8 199102 19910908 21.78 20.65 ... 10.0 1991.1110 355.79 6.0 355.09 340.74 75.12 355.79 -0.001575 1
19910207 268 2/15/1991 1991 2 7 15 199102 19910915 20.73 18.35 ... 17.0 1991.1301 356.44 6.0 355.30 340.20 75.61 356.44 -0.001825 1
19910208 269 2/22/1991 1991 2 8 22 199102 19910922 17.43 17.80 ... 24.0 1991.1493 355.73 7.0 355.02 341.52 74.72 355.73 0.001994 1
19910309 270 3/1/1991 1991 3 9 1 199103 19910901 19.43 19.33 ... 3.0 1991.1685 357.08 6.0 355.76 341.15 75.87 357.08 -0.003788 1
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
20201253 1827 12/31/2020 2020 12 53 31 202012 20201231 48.35 51.22 ... 3.0 2021.0068 415.25 7.0 413.39 391.73 135.20 415.25 -0.000385 4
20210102 1828 1/8/2021 2021 1 2 8 202101 20210108 52.14 55.51 ... NaN NaN NaN NaN NaN NaN NaN NaN NaN 1
20210103 1829 1/15/2021 2021 1 3 15 202101 20210115 52.25 54.80 ... NaN NaN NaN NaN NaN NaN NaN NaN NaN 1
20210104 1830 1/22/2021 2021 1 4 22 202101 20210122 52.28 55.22 ... NaN NaN NaN NaN NaN NaN NaN NaN NaN 1
20210105 1831 1/25/2021 2021 1 5 25 202101 20210125 52.78 55.44 ... NaN NaN NaN NaN NaN NaN NaN NaN NaN 1

1566 rows × 36 columns

In [191]:
# MERGE GDP FRAME
main_frame_granger = pd.merge(main_frame_granger,gdp_df, how = 'left', on = ['Year','Quarter'])
main_frame_granger = main_frame_granger.dropna(subset = ['gdp_date'])

#MERGE GLOBAL TEMPERATURE FRAME
main_frame_granger = pd.merge(main_frame_granger,glob_temp, how = 'left', on = ['Par_Month'])
main_frame_granger = main_frame_granger.drop(columns = ['Year_y','Month_x','Month_y']).rename(columns = {'Year_x' : 'Year'})
In [192]:
main_frame_granger_week = main_frame_granger.groupby('Weekindex').last()[[ 'Gasoline_Price_US','co2_conc','oil_spot_WTI', 'oil_spot_Brent', 'future_oil_contract_1','sugar_price_us', 'ethanol_price_us','gdp_us', 'gdp_china', 'gdp_europe', 'Celsius']]
main_frame_granger_month = main_frame_granger.groupby('Par_Month').last()[[ 'Gasoline_Price_US','co2_conc','oil_spot_WTI', 'oil_spot_Brent', 'future_oil_contract_1','sugar_price_us', 'ethanol_price_us','gdp_us', 'gdp_china', 'gdp_europe', 'Celsius']]

#Quarterly 
Par_Quarter = []
for i in range(len(main_frame_granger)):
    Par_Quarter.append(str(main_frame_granger.loc[i].Year) + str(main_frame_granger.loc[i].Quarter))
main_frame_granger['Par_Quarter'] = Par_Quarter
main_frame_granger_quarter = main_frame_granger.groupby('Par_Quarter').last()[[ 'Gasoline_Price_US','co2_conc','oil_spot_WTI', 'oil_spot_Brent', 'future_oil_contract_1','sugar_price_us', 'ethanol_price_us','gdp_us', 'gdp_china', 'gdp_europe', 'Celsius']]
In [193]:
#Weekly
main_frame_granger_week_diff = np.log(main_frame_granger_week) - np.log(main_frame_granger_week.shift(1))
main_frame_granger_week_diff.dropna(inplace = True)

#Monthly
main_frame_granger_month_diff = np.log(main_frame_granger_month) - np.log(main_frame_granger_month.shift(1))
main_frame_granger_month_diff['co2_conc'] = main_frame_granger_month_diff['co2_conc'] - main_frame_granger_month_diff['co2_conc'].shift(12)
main_frame_granger_month_diff.dropna(inplace = True)

#Quarterly
#Monthly
main_frame_granger_quarter_diff = np.log(main_frame_granger_quarter) - np.log(main_frame_granger_quarter.shift(1))
main_frame_granger_quarter_diff['co2_conc'] = main_frame_granger_quarter_diff['co2_conc'] - main_frame_granger_quarter_diff['co2_conc'].shift(4)
main_frame_granger_quarter_diff.dropna(inplace = True)
In [194]:
granger_test_weekly = grangers_causality_matrix(main_frame_granger_week_diff , variables = main_frame_granger_week_diff.columns)
granger_test_weekly
Out[194]:
Gasoline_Price_US_x co2_conc_x oil_spot_WTI_x oil_spot_Brent_x future_oil_contract_1_x sugar_price_us_x ethanol_price_us_x gdp_us_x gdp_china_x gdp_europe_x Celsius_x
Gasoline_Price_US_y 1.0000 0.0107 0.0000 0.0000 0.0000 0.3184 0.0001 0.2876 0.0316 0.1152 0.9320
co2_conc_y 0.0008 1.0000 0.2733 0.1469 0.1625 0.5762 0.1777 0.0833 0.0328 0.4439 0.0139
oil_spot_WTI_y 0.0001 0.3853 1.0000 0.0021 0.0001 0.0202 0.6880 0.4598 0.0544 0.1786 0.3762
oil_spot_Brent_y 0.0012 0.1551 0.0000 1.0000 0.0000 0.5514 0.5573 0.1553 0.0650 0.1170 0.1524
future_oil_contract_1_y 0.0001 0.3346 0.0007 0.0021 1.0000 0.0296 0.5922 0.4746 0.0469 0.1830 0.2083
sugar_price_us_y 0.4211 0.0591 0.1391 0.4332 0.1452 1.0000 0.2079 0.2404 0.1109 0.0547 0.0009
ethanol_price_us_y 0.1068 0.2418 0.8163 0.1215 0.8270 0.3212 1.0000 0.0107 0.0552 0.0132 0.0512
gdp_us_y 0.2301 0.0752 0.2975 0.3318 0.2794 0.5294 0.0475 1.0000 0.7721 0.6842 0.9077
gdp_china_y 0.0231 0.0131 0.0504 0.1316 0.1070 0.0046 0.1419 0.7232 1.0000 0.9518 0.9195
gdp_europe_y 0.0364 0.0530 0.0262 0.2219 0.0215 0.0111 0.2328 0.1735 0.7310 1.0000 0.9484
Celsius_y 0.0180 0.2374 0.6019 0.1067 0.4651 0.0541 0.0472 0.7392 0.6803 0.8688 1.0000
In [195]:
#Weekly
import seaborn as sns
corr =round(main_frame_granger_week_diff.corr(),2)

mask = np.zeros_like(corr, dtype=np.bool)
mask[np.triu_indices_from(mask)] = True

sns.heatmap(corr, xticklabels = corr.columns.values,yticklabels = corr.columns.values, annot = True,annot_kws = {'size':12}, cmap = 'vlag_r', mask = mask)
heat_map = plt.gcf()
heat_map.set_size_inches(15,8)
plt.xticks(fontsize = 15)
plt.yticks(fontsize = 15)
plt.show()
#Weekly Monthly timeframe
In [196]:
granger_test_monthly = grangers_causality_matrix(main_frame_granger_month_diff , variables = main_frame_granger_month_diff.columns)
granger_test_monthly
Out[196]:
Gasoline_Price_US_x co2_conc_x oil_spot_WTI_x oil_spot_Brent_x future_oil_contract_1_x sugar_price_us_x ethanol_price_us_x gdp_us_x gdp_china_x gdp_europe_x Celsius_x
Gasoline_Price_US_y 1.0000 0.0307 0.0000 0.0000 0.0000 0.0328 0.0002 0.0002 0.0045 0.0131 0.0007
co2_conc_y 0.3618 1.0000 0.0212 0.1194 0.0333 0.0489 0.1877 0.1848 0.9219 0.6492 0.3236
oil_spot_WTI_y 0.0431 0.0742 1.0000 0.0056 0.0061 0.1746 0.1843 0.0000 0.0186 0.0049 0.0021
oil_spot_Brent_y 0.1266 0.1566 0.4199 1.0000 0.2271 0.2490 0.0213 0.0000 0.0083 0.1704 0.0073
future_oil_contract_1_y 0.0745 0.0594 0.0634 0.0150 1.0000 0.1329 0.2200 0.0000 0.0157 0.0133 0.0015
sugar_price_us_y 0.1515 0.3224 0.1333 0.5200 0.1875 1.0000 0.2337 0.0000 0.0000 0.0037 0.1321
ethanol_price_us_y 0.1568 0.2833 0.1550 0.1290 0.1143 0.0775 1.0000 0.1765 0.1328 0.3425 0.0010
gdp_us_y 0.0614 0.1676 0.1266 0.2762 0.1455 0.5802 0.0840 1.0000 0.1302 0.0004 0.0030
gdp_china_y 0.0001 0.9226 0.0616 0.2349 0.0816 0.0000 0.0406 0.0000 1.0000 0.0000 0.0159
gdp_europe_y 0.0195 0.2961 0.1373 0.2046 0.1202 0.1557 0.0681 0.0000 0.6803 1.0000 0.0245
Celsius_y 0.5787 0.2875 0.2691 0.6878 0.3270 0.1079 0.4608 0.0051 0.0107 0.3562 1.0000
In [197]:
#Monthly
import seaborn as sns
corr =round(main_frame_granger_month_diff.corr(),2)

mask = np.zeros_like(corr, dtype=np.bool)
mask[np.triu_indices_from(mask)] = True

sns.heatmap(corr, xticklabels = corr.columns.values,yticklabels = corr.columns.values, annot = True,annot_kws = {'size':12}, cmap = 'vlag_r', mask = mask)
heat_map = plt.gcf()
heat_map.set_size_inches(15,8)
plt.xticks(fontsize = 15)
plt.yticks(fontsize = 15)
plt.show()
#Monthly timeframe
In [198]:
granger_test_quarterly = grangers_causality_matrix(main_frame_granger_quarter_diff , variables = main_frame_granger_week_diff.columns)
granger_test_quarterly
Out[198]:
Gasoline_Price_US_x co2_conc_x oil_spot_WTI_x oil_spot_Brent_x future_oil_contract_1_x sugar_price_us_x ethanol_price_us_x gdp_us_x gdp_china_x gdp_europe_x Celsius_x
Gasoline_Price_US_y 1.0000 0.0000 0.0001 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0174 0.0543
co2_conc_y 0.0015 1.0000 0.0032 0.0013 0.0033 0.0015 0.0002 0.1042 0.3197 0.1017 0.0005
oil_spot_WTI_y 0.0708 0.0000 1.0000 0.3872 0.2575 0.0301 0.0000 0.0000 0.0000 0.2649 0.3292
oil_spot_Brent_y 0.0025 0.0000 0.1952 1.0000 0.2362 0.0023 0.0000 0.0000 0.0000 0.1763 0.1086
future_oil_contract_1_y 0.0459 0.0000 0.3050 0.4711 1.0000 0.0304 0.0000 0.0000 0.0000 0.2627 0.2970
sugar_price_us_y 0.0000 0.0000 0.0000 0.0000 0.0000 1.0000 0.0042 0.0000 0.0396 0.0007 0.0102
ethanol_price_us_y 0.5348 0.1441 0.0833 0.0052 0.0781 0.0937 1.0000 0.1432 0.0001 0.2695 0.0001
gdp_us_y 0.0001 0.0000 0.0471 0.0520 0.0373 0.2413 0.0000 1.0000 0.0003 0.0087 0.1570
gdp_china_y 0.0000 0.0000 0.0001 0.0000 0.0001 0.0022 0.0003 0.0000 1.0000 0.0039 0.0080
gdp_europe_y 0.0078 0.0010 0.0596 0.0954 0.0548 0.5004 0.0513 0.0000 0.0188 1.0000 0.5495
Celsius_y 0.0000 0.0056 0.0000 0.0000 0.0000 0.0122 0.0000 0.0661 0.0000 0.0399 1.0000
In [199]:
#Quarterly
import seaborn as sns
corr =round(granger_test_quarterly.corr(),2)

mask = np.zeros_like(corr, dtype=np.bool)
mask[np.triu_indices_from(mask)] = True

sns.heatmap(corr, xticklabels = corr.columns.values,yticklabels = corr.columns.values, annot = True,annot_kws = {'size':12}, cmap = 'vlag_r', mask = mask)
heat_map = plt.gcf()
heat_map.set_size_inches(15,8)
plt.xticks(fontsize = 15)
plt.yticks(fontsize = 15)
plt.show()
#Weekly Monthly timeframe
In [200]:
main_frame_granger_week_diff[['index']] = 0
main_frame_granger_month_diff[['index']] = 1
main_frame_granger_quarter_diff[['index']] = 2
merge_df = [main_frame_granger_week_diff,main_frame_granger_month_diff,main_frame_granger_quarter_diff]
merge_result = pd.concat(merge_df)
merge_result_w_index = merge_result.set_index('index')
In [201]:
merge_result = merge_result.rename(columns = {'Gasoline_Price_US': 'Gasoline Price US','co2_conc': 'CO2 Concentration','oil_spot_WTI':'Oil Spot WTI','future_oil_contract_1':'Oil Futures','sugar_price_us':'Sugar Price US','ethanol_price_us':'Ethanol Price US','gdp_us':'US GDP','gdp_china':'China GDP','gdp_europe':'Europe GDP','Celsius':'Global Temp'})
merge_result_w_index  = merge_result_w_index.rename(columns = {'Gasoline_Price_US': 'Gasoline Price US','co2_conc': 'CO2 Concentration','oil_spot_WTI':'Oil Spot WTI','future_oil_contract_1':'Oil Futures','sugar_price_us':'Sugar Price US','ethanol_price_us':'Ethanol Price US','gdp_us':'US GDP','gdp_china':'China GDP','gdp_europe':'Europe GDP','Celsius':'Global Temp'})
In [202]:
merge_result_w_index
Out[202]:
Gasoline Price US CO2 Concentration Oil Spot WTI oil_spot_Brent Oil Futures Sugar Price US Ethanol Price US US GDP China GDP Europe GDP Global Temp
index
0.0 -0.024955 0.000993 -0.053039 -0.059054 -0.045978 -0.008348 -0.017094 0.000000 0.000000 0.000000 0.000000
0.0 -0.009875 -0.000575 -0.029199 0.001280 -0.039180 0.028337 0.008584 0.000000 0.000000 0.000000 0.000000
0.0 0.013078 -0.001204 -0.028171 0.001540 -0.027449 0.002250 0.016394 0.000000 0.000000 0.000000 0.000000
0.0 0.010055 -0.001546 0.086700 0.090788 0.088085 0.001123 0.055350 0.000000 0.000000 0.000000 0.000000
0.0 0.001371 -0.000289 0.010099 0.044891 0.014868 0.040647 0.064958 0.000000 0.000000 0.000000 0.000000
... ... ... ... ... ... ... ... ... ... ... ...
2.0 0.012310 -0.000063 -0.013171 0.065958 -0.012212 -0.097449 -0.103413 0.008025 0.098744 0.011274 0.049393
2.0 -0.226387 -0.001321 -0.482659 -0.492103 -0.479909 0.115365 -0.023623 0.009778 -0.171307 0.012655 0.069796
2.0 0.138034 -0.000181 0.287516 0.295119 0.282706 0.011236 0.069258 0.010110 0.106523 0.005814 0.211844
2.0 -0.001180 0.001663 -0.033621 -0.006054 -0.028161 0.002391 0.112399 0.009818 0.038951 0.002374 -0.146603
2.0 0.007840 -0.000894 -0.039427 -0.077577 -0.044771 -0.030722 -0.018780 0.009567 0.097435 0.014080 -0.010582

694 rows × 11 columns

In [203]:
#Weekly Gasoline price problem
from matplotlib.ticker import FormatStrFormatter
from pandas.plotting import scatter_matrix


%matplotlib inline
plt.style.use("default")

plot_fig = main_frame_granger_week_diff.rename(columns = {'Gasoline_Price_US': 'Gasoline Price US return','co2_conc': 'Change in CO2 Concentration','oil_spot_WTI':'Oil Spot WTI return','future_oil_contract_1':'Oil Futures return','sugar_price_us':'Sugar Price US return','ethanol_price_us':'Ethanol Price US return','gdp_us':'Change in US GDP','gdp_china':'Change in China GDP','gdp_europe':'Change in Europe GDP','Celsius':'Change in Global Temp'})
plot_fig1 = plot_fig[['Gasoline Price US return','Oil Spot WTI return','Oil Futures return','Sugar Price US return','Ethanol Price US return']]
scatter_matrix = pd.plotting.scatter_matrix(plot_fig1, alpha=0.2, marker = 'o', figsize = (8,8),diagonal = 'kde')
for ax in scatter_matrix.ravel():
    ax.set_xlabel(ax.get_xlabel(), fontsize = 10, rotation = 0)
    ax.set_ylabel(ax.get_ylabel(), fontsize = 10, rotation = 90)
    ax.yaxis.set_major_formatter(FormatStrFormatter('%.1f'))
plt.suptitle('Weekly correlation plot - change in Gasoline', size = 12, weight = 'bold',va = 'bottom', x= 0.5, y= 0.9)
plt.show()

#Weekly CO2 problem

plot_fig2 = plot_fig[['Change in CO2 Concentration', 'Oil Spot WTI return','Change in US GDP', 'Change in China GDP', 'Change in Europe GDP', 'Change in Global Temp']]
scatter_matrix = pd.plotting.scatter_matrix(plot_fig2, alpha=0.2, marker = 'o', figsize = (8,8),diagonal = 'kde')
for ax in scatter_matrix.ravel():
    ax.set_xlabel(ax.get_xlabel(), fontsize = 10, rotation = 0)
    ax.set_ylabel(ax.get_ylabel(), fontsize = 10, rotation = 90)
    ax.yaxis.set_major_formatter(FormatStrFormatter('%.1f'))
plt.suptitle('Weekly correlation plot - change Carbon Dioxide Concentration', size = 12, weight = 'bold',va = 'bottom', x= 0.5, y= 0.9)
plt.show()
In [204]:
merge_result_w_index.columns
Out[204]:
Index(['Gasoline Price US', 'CO2 Concentration', 'Oil Spot WTI',
       'oil_spot_Brent', 'Oil Futures', 'Sugar Price US', 'Ethanol Price US',
       'US GDP', 'China GDP', 'Europe GDP', 'Global Temp'],
      dtype='object')
In [205]:
from pandas.plotting import scatter_matrix
import pandas as pd
from sklearn import datasets

color_wheel = {1: "#0392cf", #b
               2: "#7bc043", #g
               3: "#ee4035"} #r
colors = merge_result_w_index.index.map(lambda x: color_wheel.get(x + 1))
ax = scatter_matrix(merge_result_w_index[['Gasoline Price US','Oil Spot WTI','Oil Futures','Sugar Price US','Ethanol Price US']], color=colors
                    , alpha=0.5, figsize=(4, 4), diagonal='kde', marker = '.')
for ax in ax.ravel():
    ax.set_xlabel(ax.get_xlabel().replace(' ', '\n'), fontsize = 7, rotation = 0)
    ax.set_ylabel(ax.get_ylabel().replace(' ', '\n'), fontsize = 7, rotation = 90)
    ax.yaxis.set_major_formatter(FormatStrFormatter('%.1f'))
    ax.yaxis.set_ticks([])
    ax.xaxis.set_ticks([])
    
plt.suptitle('Correlation plot - change in Gasoline', size = 12, weight = 'bold',va = 'bottom', x= 0.5, y= 0.93)

handles = [plt.plot([],[],color=plt.cm.brg(i/2.), ls="", marker="o", \
                    markersize=np.sqrt(10))[0] for i in range(3)]
handles = [handles[0],handles[2],handles[1]]
labels=["Weekly", "Monthly", "Quarterly"]
plt.legend(handles, labels, loc=(1.02,0))
plt.show()
In [206]:
from pandas.plotting import scatter_matrix
import pandas as pd
from sklearn import datasets

color_wheel = {1: "#0392cf", #b
               2: "#7bc043", #g
               3: "#ee4035"} #r
colors = merge_result_w_index.index.map(lambda x: color_wheel.get(x + 1))
ax = scatter_matrix(merge_result_w_index[['Gasoline Price US','Oil Spot WTI','Oil Futures','Sugar Price US','Ethanol Price US']], color=colors
                    , alpha=0.5, figsize=(4, 4), diagonal='kde', marker = '.')
for i in range(np.shape(ax)[0]):
    for j in range(np.shape(ax)[1]):
        if i < j:
            ax[i,j].set_visible(False)

for ax in ax.ravel():
    
    ax.set_xlabel(ax.get_xlabel().replace(' ', '\n'), fontsize = 7, rotation = 0, weight = 'medium')
    ax.set_ylabel(ax.get_ylabel().replace(' ', '\n'), fontsize = 7, rotation = 90, weight = 'medium')
    ax.yaxis.set_major_formatter(FormatStrFormatter('%.1f'))
    ax.xaxis.set_major_formatter(FormatStrFormatter('%.1f'))
    ax.yaxis.set_ticks([])
    ax.xaxis.set_ticks([])

plt.suptitle('Correlation plot of change in \n variables VS change in Gasoline', size = 12, weight = 'bold',va = 'bottom', x= 0.5, y= 0.93)



handles = [plt.plot([],[],color=plt.cm.brg(i/2.), ls="", marker="o", \
                    markersize=np.sqrt(10))[0] for i in range(3)]
handles = [handles[0],handles[2],handles[1]]
labels=["Weekly", "Monthly", "Quarterly"]
plt.legend(handles, labels, loc=(1.02,0))
plt.show()
In [207]:
ax = scatter_matrix(merge_result_w_index[['Gasoline Price US','Oil Spot WTI','Oil Futures','Sugar Price US','Ethanol Price US']], color=colors
                    , alpha=0.5, figsize=(4, 4), diagonal='kde', marker = '.')
In [208]:
from pandas.plotting import scatter_matrix
import pandas as pd
from sklearn import datasets

color_wheel = {1: "#0392cf", #b
               2: "#7bc043", #g
               3: "#ee4035"} #r
colors = merge_result_w_index.index.map(lambda x: color_wheel.get(x + 1))
ax = scatter_matrix(merge_result_w_index[['CO2 Concentration', 'Oil Spot WTI','US GDP', 'China GDP', 'Europe GDP', 'Global Temp']], color=colors
                    , alpha=0.5, figsize=(4, 4), diagonal='kde', marker = '.')

for i in range(np.shape(ax)[0]):
    for j in range(np.shape(ax)[1]):
        if i < j:
            ax[i,j].set_visible(False)

for ax in ax.ravel():
    ax.set_xlabel(ax.get_xlabel().replace(' ', '\n'), fontsize = 7, rotation = 0, weight = 'medium')
    ax.set_ylabel(ax.get_ylabel().replace(' ', '\n'), fontsize = 7, rotation = 90, weight = 'medium')
    ax.yaxis.set_major_formatter(FormatStrFormatter('%.1f'))
    ax.yaxis.set_ticks([])
    ax.xaxis.set_ticks([])
    
plt.suptitle('Correlation plot of change in \n variables VS CO2 Concentration', size = 12, weight = 'bold',va = 'bottom', x= 0.5, y= 0.93)

handles = [plt.plot([],[],color=plt.cm.brg(i/2.), ls="", marker="o", \
                    markersize=np.sqrt(10))[0] for i in range(3)]
handles = [handles[0],handles[2],handles[1]]
labels=["Weekly", "Monthly", "Quarterly"]
plt.legend(handles, labels, loc=(1.02,0))
plt.show()
In [209]:
from pandas.plotting import scatter_matrix
import pandas as pd
from sklearn import datasets

color_wheel = {1: "#0392cf", #b
               2: "#7bc043", #g
               3: "#ee4035"} #r
colors = merge_result_w_index.index.map(lambda x: color_wheel.get(x + 1))
ax = scatter_matrix(merge_result_w_index[['CO2 Concentration', 'Oil Spot WTI','US GDP', 'China GDP', 'Europe GDP']], color=colors
                    , alpha=0.5, figsize=(4, 4), diagonal='kde', marker = '.')
for ax in ax.ravel():
    ax.set_xlabel(ax.get_xlabel().replace(' ', '\n'), fontsize = 7, rotation = 0)
    ax.set_ylabel(ax.get_ylabel().replace(' ', '\n'), fontsize = 7, rotation = 90)
    ax.yaxis.set_major_formatter(FormatStrFormatter('%.1f'))
    ax.xaxis.set_major_formatter(FormatStrFormatter('%.1f'))
plt.suptitle('Correlation plot - change in CO2 Concentration', size = 12, weight = 'bold',va = 'bottom', x= 0.5, y= 0.93)

handles = [plt.plot([],[],color=plt.cm.brg(i/2.), ls="", marker="o", \
                    markersize=np.sqrt(10))[0] for i in range(3)]
handles = [handles[0],handles[2],handles[1]]
labels=["Weekly", "Monthly", "Quarterly"]
plt.legend(handles, labels, loc=(1.02,0))
plt.show()
In [210]:
main_frame_granger.columns
Out[210]:
Index(['Weekindex', 'Date', 'Year', 'Week', 'Day', 'Par_Month', 'Par_Day',
       'oil_spot_WTI', 'oil_spot_Brent', 'future_oil_contract_1',
       'sugar_price_us', 'ethanol_price_us', 'chg_oil_spot_WTI',
       'chg_oil_spot_Brent', 'chg_oil_spot_WTI_Positive',
       'chg_oil_spot_WTI_Negative', 'chg_oil_future_contract1',
       'chg_oil_future_contract1_Positive',
       'chg_oil_future_contract1_Negative', 'Gasoline_Price_US',
       'chg_Gasoline_price_US', 'chg_Gasoline_price_US_Positive',
       'chg_Gasoline_price_US_future', 'Date_edited', 'year', 'day', 'decimal',
       'average', 'ndays', '1_year_ago', '10_years_ago', 'increase_since_1800',
       'co2_conc', 'chg_co2_conc', 'Quarter', 'gdp_date', 'gdp_us',
       'gdp_china', 'gdp_europe', 'Celsius', 'Month', 'Par_Quarter'],
      dtype='object')
In [211]:
main_frame_granger_week = main_frame_granger.groupby('Weekindex').last()[[ 'Date','Gasoline_Price_US','co2_conc','oil_spot_WTI', 'oil_spot_Brent', 'future_oil_contract_1','sugar_price_us', 'ethanol_price_us','gdp_us', 'gdp_china', 'gdp_europe', 'Celsius']]
main_frame_granger_month = main_frame_granger.groupby('Par_Month').last()[[ 'Date','Gasoline_Price_US','co2_conc','oil_spot_WTI', 'oil_spot_Brent', 'future_oil_contract_1','sugar_price_us', 'ethanol_price_us','gdp_us', 'gdp_china', 'gdp_europe', 'Celsius']]

#Quarterly 
Par_Quarter = []
for i in range(len(main_frame_granger)):
    Par_Quarter.append(str(main_frame_granger.loc[i].Year) + str(main_frame_granger.loc[i].Quarter))
main_frame_granger['Par_Quarter'] = Par_Quarter
main_frame_granger_quarter = main_frame_granger.groupby('Par_Quarter').last()[[ 'Date','Gasoline_Price_US','co2_conc','oil_spot_WTI', 'oil_spot_Brent', 'future_oil_contract_1','sugar_price_us', 'ethanol_price_us','gdp_us', 'gdp_china', 'gdp_europe', 'Celsius']]
In [212]:
main_frame_granger_week.to_csv('weeklygg.csv')
main_frame_granger_month.to_csv('monthlygg.csv')
main_frame_granger_quarter.to_csv('quarterlygg.csv')